Note that there are some explanatory texts on larger screens.

plurals
  1. POYii sql query bindings, with params, do not work properly
    text
    copied!<p>I'm new to Yii and everything seems good, but the problem is, when I`m using the binding params, like (DAO stile): </p> <pre><code>$command = $this-&gt;conn-&gt;createCommand($sql); $command-&gt;bindColumn("title", "test_title"); $result = $command-&gt;query(); </code></pre> <p>or (Active Record):</p> <pre><code>$row = Movies::model()-&gt;find("m_id=:m_id", array(":m_id"=&gt;27)); or $row = Movies::model()-&gt;findByPk(24); </code></pre> <p>I've tried everything: 1) added a config param to mysql config. in main.php - 'enableParamLogging' => true<br> 2) changed strings from ' to " 3) added another param just in case of mysql versions - 'emulatePrepare'=>true</p> <p>Nothing works for me. I thought that the problem is in params, but bindColumn method doesn't use it, so my presumption is that some module of Yii hasn't been include in config file or something like that. </p> <p>My model looks like this (created in /models dir): </p> <pre><code>class Movies extends CActiveRecord { public static function model($className = __CLASS__) { parent::model($className); } } </code></pre> <p>Just for everybody to avoid unnecessary questions: the database is configured properly in main.php conf file, there is a table <strong>movies</strong>, there is a PKs 24 and 27 also. </p> <p>All native SQL works fine, except using in DAO special methods to bind some params and if in AR using findByPk or find. I hope that this is clear, guys don't bother me with obvious simple technical possibilities, that I can (as U presume) did wrong.</p> <p>PS Another helpful info - when calling </p> <pre><code>$command-&gt;bindColumn("title", "test_title"); </code></pre> <p>FW's throwing an Exception - <strong>CDbCommand and its behaviors do not have a method or closure named "bindColumn"</strong>. So, as mentioned above, I think that Yii don't see those special methods and this is certain. How can I repair it?</p> <p>Ok, why this code don't work either? There is no Exceptions, just blank page.</p> <pre><code>$sql = "SELECT title, year_made FROM movies WHERE year_made=':ym'"; $command = $this-&gt;conn-&gt;createCommand($sql); $command-&gt;bindParam(":ym", "2012", PDO::PARAM_STR); $result = $command-&gt;query(); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload