问题描述
关于PDO的ATTR_EMULATE_PREPARES属性,这只是一个简单的问题-简而言之,将其保留为默认值(true)时,一切正常.但是禁用它,好吧,我什至没有得到PHP错误消息,只是浏览器警告告诉我连接已重置".
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
)
但是我有时间将PDO :: ATTR_EMULATE_PREPARES的值设置为false,这只会失败,然后再次失败,直到我将其恢复为原始值为止.我能做些什么来找出导致这种情况的原因吗?或者我错过了一些非常简单的事情?
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?
我的PHP版本当前为5.4.3,而MySQL为5.5.24
My PHP version is currently 5.4.3 and MySQL is 5.5.24
推荐答案
在某些PHP版本中,这似乎是一个错误:
This looks to be a bug in certain PHP versions:
https://bugs.php.net/bug.php?id=61411
似乎两者都运行有问题
PDO::ATTR_PERSISTENT => true
和
PDO::ATTR_EMULATE_PREPARES => true
您在PDO的attribute/options数组中.
Which you have in your PDO attributes/options array.
这篇关于禁用PDO :: ATTR_EMULATE_PREPARES导致“未知"问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!