Yii Framework Forum: [SOLVED] I can not use CActiveDataProvider - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

[SOLVED] I can not use CActiveDataProvider Rate Topic: -----

#1 User is offline   Co-k-ine 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 97
  • Joined: 29-March 10

Posted 25 July 2010 - 03:04 PM

Hello every body

I want create a Private Messaging, but I can not use CActiveDataProvider !

in my controller i have :

<?php

public function actionIndex()
	{
		$uname = strtolower(Yii::app()->user->name);
		$this->render('index',array(
			'dataProvider'=>new CActiveDataProvider('message', array(
				'criteria' => array('condition' => 'LOWER(to) = '.$uname
		)))));

	
	}




And yii returns this error message :

CDbCommand failed to execute the SQL statement: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'to) = root' at line 1

Where is a problem ?
0

#2 User is offline   frantic 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 172
  • Joined: 01-March 10
  • Location:Saint-Petersburg

Posted 25 July 2010 - 03:46 PM

Try:
array(
        'condition' => 'LOWER(to) = :to',
        'params' => array(':to' => strtolower($uname)),
)

0

#3 User is offline   Co-k-ine 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 97
  • Joined: 29-March 10

Posted 26 July 2010 - 05:05 AM

It don't work :

Quote

CDbCommand failed to execute the SQL statement: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'to) = 'root'' at line 1

0

#4 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,359
  • Joined: 12-October 09
  • Location:Croatia

Posted 26 July 2010 - 05:54 AM

You get this error because the filed name "to" is a reserved word in mysql

reserved words in mysql - http://dev.mysql.com...rved-words.html

for reserved words you have to quote them... so instead of using lower(to) use lower('to')
Find more about me.... btw. Do you know your WAN IP?
0

#5 User is offline   Co-k-ine 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 97
  • Joined: 29-March 10

Posted 26 July 2010 - 01:47 PM

View Postmdomba, on 26 July 2010 - 05:54 AM, said:

You get this error because the filed name "to" is a reserved word in mysql

reserved words in mysql - http://dev.mysql.com...rved-words.html

for reserved words you have to quote them... so instead of using lower(to) use lower('to')


Thanks for your help, I doesn't know this rules of mysql.

But I have yet a problem.

In my pm tables i have :

Posted Image

And in my controller :

<?php
public function actionIndex()
	{
		$uname = strtolower(Yii::app()->user->name);
		$this->render('index',array(
			'dataProvider'=>new CActiveDataProvider('message', array(
				'criteria' => array(
        'condition' => 'LOWER(\'to\') = :to',
        'params' => array(':to' => $uname),
		)
		))));

	
	}


$uname = 'root';

I should have 2 results but i have "No results found."

Am I doing something wrong?
0

#6 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,359
  • Joined: 12-October 09
  • Location:Croatia

Posted 26 July 2010 - 02:25 PM

Try to use

'condition'=>"LOWER('to') = :to",


if it does not work... then I would suggest to rename that field so that you don't use a reserved word
Find more about me.... btw. Do you know your WAN IP?
0

#7 User is offline   Co-k-ine 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 97
  • Joined: 29-March 10

Posted 26 July 2010 - 02:54 PM

View Postmdomba, on 26 July 2010 - 02:25 PM, said:

Try to use

'condition'=>"LOWER('to') = :to",


if it does not work... then I would suggest to rename that field so that you don't use a reserved word

It does not work ...

I have genered my db shemas whith "mysql workbench". How to make the field is not defined as: reserved words ? (sorry for my stupid question)
0

#8 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,359
  • Joined: 12-October 09
  • Location:Croatia

Posted 27 July 2010 - 01:44 AM

I don't use workbech but there should be an option to rename a field and just rename fields

from => fromuser
to => touser

also... as the fields in the table are all lowercase.. try to use without the function "lower()" just to see if you get any result...
Find more about me.... btw. Do you know your WAN IP?
0

#9 User is offline   Co-k-ine 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 97
  • Joined: 29-March 10

Posted 27 July 2010 - 05:15 AM

View Postmdomba, on 27 July 2010 - 01:44 AM, said:

I don't use workbech but there should be an option to rename a field and just rename fields

from => fromuser
to => touser

also... as the fields in the table are all lowercase.. try to use without the function "lower()" just to see if you get any result...


I have rename fields and when i use :
<?php

public function actionIndex()
	{
		$uname = strtolower(Yii::app()->user->name);
		$this->render('index',array(
			'dataProvider'=>new CActiveDataProvider('message', array(
				'criteria' => array(
        'condition' => 'touser = :touser',
        'params' => array(':touser' => $uname),
		)
		))));

	
	}


it's work. But when i use lower it does not work :

<?php

	public function actionIndex()
	{
		$uname = strtolower(Yii::app()->user->name);
		$this->render('index',array(
			'dataProvider'=>new CActiveDataProvider('message', array(
				'criteria' => array(
        'condition' => "LOWER('touser') = :touser",
        'params' => array(':touser' => $uname),
		)
		))));

	
	}



i have: "No results found." why ?
0

#10 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,359
  • Joined: 12-October 09
  • Location:Croatia

Posted 27 July 2010 - 05:24 AM

I think it does not work because somewhere the quotes got prefixed with a backslash like "lower(\'touser\')"

but now that you are not using a reserved word you can use "lower('touser')" without quotes as "lower(touser)"...
Find more about me.... btw. Do you know your WAN IP?
0

#11 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,359
  • Joined: 12-October 09
  • Location:Croatia

Posted 27 July 2010 - 05:26 AM

On the other side... if that is your table... and you are the only one inserting records in it... and you use only lowercase... why don't you insert lowercase usernames (convert to lowercase before insert)... so that you don't have to use the lower() function in the select...
Find more about me.... btw. Do you know your WAN IP?
0

#12 User is offline   Co-k-ine 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 97
  • Joined: 29-March 10

Posted 27 July 2010 - 05:29 AM

It's work !!!

Thank for your help mdomba !
Without you I could never happen. Thank you very much
0

#13 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,359
  • Joined: 12-October 09
  • Location:Croatia

Posted 27 July 2010 - 05:41 AM

No problem... I'm glad I can help...
Find more about me.... btw. Do you know your WAN IP?
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users