Just a quick question regarding PDO's ATTR_EMULATE_PREPARES attribute- simply put, while left on default (true) everything works fine and dandy. Disable it however and, well, I don't even get a PHP error message, just a browser warning telling me that "the connection was reset".
For reference here is a sample of the code I was using
<?php
include_once("config.php");
try {
$dbh = new PDO
(
"mysql:host=". DB_SERVER .";dbname=" . DB_NAME,
DB_USER,
DB_PASS,
array
(
PDO::ATTR_PERSISTENT => true,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => true
)
);
} catch(PDOException $e) {
echo "<pre>";
print_r("Error: " . $e);
echo "</pre>";
die();
}
$idNum = "1";
$sth = $dbh->prepare("SELECT * FROM `table` WHERE `id` = ?;");
$sth->bindParam(1,$idNum);
$sth->execute();
$res = $sth->fetch();
?>
<pre>
<?=print_r($res); ?>
</pre>
Which nicely returns the query from my lovely test table...
Array
(
[id] => 1
[field1] => q12w3e4r5t6y7u8i9
[field2] => kijhgbfvcdoikujyh
)
However were I to have the temerity to set the value of PDO::ATTR_EMULATE_PREPARES to false it would simply fail, and fail again until I return it to its original value. Is there anything I can do to find out what is causing this or have I missed something really simple?
My PHP version is currently 5.4.3 and MySQL is 5.5.24
This looks to be a bug in certain PHP versions:
https://bugs.php.net/bug.php?id=61411
It seems there is a problem running both
PDO::ATTR_PERSISTENT => true
and
PDO::ATTR_EMULATE_PREPARES => true
Which you have in your PDO attributes/options array.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With