PDO operation, after setting the ATTR_EMULATE_PREPARES attribute to false, I found that prepare is still simulated locally
<code><?php //连接数据库部分 try{ $dbh = new PDO('mysql:dbname=test;host=localhost','root','root'); //设置捕获异常 $dbh -> setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION); //设置禁止本地模拟prepare $dbh -> setAttribute(PDO::ATTR_EMULATE_PREPARES,false); $dbh -> exec('set names gbk'); }catch(PDOException $e){ echo '数据库连接失败:'.$e->getMessage(); exit; } $query = "SELECT * FROM news WHERE tid=?"; $stmt = $dbh -> prepare($query); $tid = $_GET['id']; //将参数添加到SQL查询中 $stmt -> bindParam(1,$tid); $stmt -> execute(); ?></code>
mysql log:
<code>160614 13:14:12 27 Connect root@localhost on test 27 Query set names gbk 27 Query SELECT * FROM news WHERE tid='1' 27 Quit </code>
I found that it was not as described: "Set this attribute to false, and the simulation prepare will not be performed locally"
php version 5.2.17
Supplementary content:
PDO::ATTR_EMULATE_PREPARES enables or disables emulation of prepared statements. Some drivers have no or limited support for local preprocessing. Use this setting to force PDO to always emulate prepared statements (if TRUE ), or try to use native prepared statements (if FALSE ). If the driver cannot successfully prepare the current query, it will always fall back to simulating prepared statements .
Is this a problem caused by the driver not successfully preprocessing the current query?
PDO operation, after setting the ATTR_EMULATE_PREPARES attribute to false, I found that prepare is still simulated locally
<code><?php //连接数据库部分 try{ $dbh = new PDO('mysql:dbname=test;host=localhost','root','root'); //设置捕获异常 $dbh -> setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION); //设置禁止本地模拟prepare $dbh -> setAttribute(PDO::ATTR_EMULATE_PREPARES,false); $dbh -> exec('set names gbk'); }catch(PDOException $e){ echo '数据库连接失败:'.$e->getMessage(); exit; } $query = "SELECT * FROM news WHERE tid=?"; $stmt = $dbh -> prepare($query); $tid = $_GET['id']; //将参数添加到SQL查询中 $stmt -> bindParam(1,$tid); $stmt -> execute(); ?></code>
mysql log:
<code>160614 13:14:12 27 Connect root@localhost on test 27 Query set names gbk 27 Query SELECT * FROM news WHERE tid='1' 27 Quit </code>
I found that it was not as described: "Set this attribute to false, and the simulation prepare will not be performed locally"
php version 5.2.17
Supplementary content:
PDO::ATTR_EMULATE_PREPARES enables or disables emulation of prepared statements. Some drivers have no or limited support for local preprocessing. Use this setting to force PDO to always emulate prepared statements (if TRUE ), or try to use native prepared statements (if FALSE ). If the driver cannot successfully prepare the current query, it will always fall back to simulating prepared statements .
Is this a problem caused by the driver not successfully preprocessing the current query?
I found the problem. I am using the win environment. When I use the php5.2.x environment under Linux, I can preprocess smoothly