Hi,

I have received a reply from Lukas Foldyna who helpfully suggested the
following:

try this $db->getConnection()->setAttribute (PDO::ATTR_EMULATE_PREPARES,
true);

I assumed he meant $db to be an instance of Zend_Db_Adapter returned from
the Zend_Db factory.  However getConnection is not a method associated with
the returned object.

To test the solution I implemented a simple test away from the FrameWork.  I
tried this:

try {
   $dbh = new PDO('mysql:host=localhost;dbname='.DBNAME, DBUSER, DBPASS);
   $dbh->setAttribute (PDO::ATTR_EMULATE_PREPARES, true);
   $result = $dbh->query('SELECT * FROM users');
} catch (PDOException $e) {
   print "Error!: " . $e->getMessage() . "<br/>";
   die();
}

foreach ($result as $row) {
        echo "<p>".$row['username']."</p>";
        }

This does indeed work and I was able to receive results from the database. 
I had tested the PDO away from the FrameWork and I was receiving the same
error so this modification of the PDO attribute seems to have done the
trick.

Can someone let me know how to incorporate this into the FrameWork.  I've
had a look at the Manual and API but I can't see how to set this attribute.

I originally assumed that I simply passed it to the Factory class via the
config array but this did not work.  I tried:
$config[ATTR_EMULATE_PREPARES] = true;
$config["ATTR_EMULATE_PREPARES"] = true;
$config[PDO::ATTR_EMULATE_PREPARES] = true;
$config["PDO::ATTR_EMULATE_PREPARES"] = true;

None of the above variations worked.  ATTR_EMULATE_PREPARES does not appear
in the list of PDO constant values discovered by the Db.php script.  Is this
why I can't set it?

Why do I have to set this attribute for scripts running on one server but
not the other?  Can anyone with more experience with PDO and the Zend_Db
class explain what the original error message means and why setting this
attribute solves it? Perhaps I can solve it by adjusting my MySql settings
rather than the PDO attributes?

How do I set the attribute using the Zend_Db factory or corresponding
Zend_Db_Adapter class?

Cheers,

Sam
-- 
View this message in context: 
http://www.nabble.com/PDOException-with-message-SQLSTATE-HY000-%3A-General-error%3A-2036-tf3239563s16154.html#a9041523
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to