Yii Framework Forum: Cdbcommand Failed To Execute The Sql Statement: Sqlstate[42000]: Syntax Error Or Access Violation: - Yii Framework Forum

Jump to content

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

Cdbcommand Failed To Execute The Sql Statement: Sqlstate[42000]: Syntax Error Or Access Violation: Rate Topic: -----

#1 User is offline   swampone 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 40
  • Joined: 28-March 11

Posted 18 December 2012 - 07:33 PM

Everything works fine on localhost but after i have uploaded to host i get the following error
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 '' at line 3. The SQL statement executed was: SELECT *
FROM `Image`
WHERE

It looks like its not recognizing the where parameters, but why it does locally but not once I have uploaded to a host
Here is the code that i have in my view that is generating the error
<?php
 $rows = Yii::app()->db->createCommand()
    ->from("Image")
    ->where(array("types = admin"))
    ->queryAll();
foreach($rows as $row)
{

    $imghtml=CHtml::image(Yii::app()->request->baseUrl.'/images/thumb/'.$row['image']);
    echo '<a class = "image" href="'.Yii::app()->request->baseUrl.'/generator/create?image='.$row['image'].'">'.$imghtml.'</a>   ';

}

?>

0

#2 User is offline   Da:Sourcerer 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,222
  • Joined: 30-March 11
  • Location:Berlin, Germany

Posted 18 December 2012 - 11:50 PM

It's interesting it worked at all. The signature of CDbCommand.where( is quite different from the way you invoke it. I'm also not quite sure where that 'admin' string comes from. IMHO, this should work a lot better:
<?php
 $rows = Yii::app()->db->createCommand()
    ->from("Image")
    ->where("types = 'admin'")
    ->queryAll();

And while we're at it: You should really pass the href-part of your generated links through CHtml::encode().
programmer /ˈprəʊgramə/, noun: a device that converts ►coffee into ►code
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