Just a quick question regarding the PDO attribute ATTR_EMULATE_PREPARES is simply to put, and left by default (true) everything works fine and dandy. However, turn it off and, well, I didn’t even receive a PHP error message, just a browser warning telling me that "the connection was reset".
For reference, here is a sample code that I used
<?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 pleasantly returns a query from my beautiful test pattern ...
Array ( [id] => 1 [field1] => q12w3e4r5t6y7u8i9 [field2] => kijhgbfvcdoikujyh )
However, if I had the time to set the PDO :: ATTR_EMULATE_PREPARES value to false, it would simply fail and work again until I returned its original value. Is there anything I can do to find out what causes this, or am I missing something really simple?
My PHP version is currently 5.4.3 and MySQL is 5.5.24
source share