我是否会失去理智,或者Postgres PDO驱动程序是否不支持预备语句,而是模仿客户端?
以下代码为prepare()调用返回NO ERROR,即使它应该.相反,它在调用execute()时返回适用的错误.
编辑:因为根据DanielVérité我错了,我添加了他建议的代码.我仍然得到错误.我的代码现在看起来如下,添加了Daniel的行.
<?php
$pdo = new PDO("pgsql:host=myhost;dbname=mydatabase");
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); // as suggested by Daniel
$sth = $pdo->prepare('COMPLETE GARBAGE');
echo "[prepare] errorInfo = " . print_r($sth->errorInfo(), true);
$sth->execute();
echo "[execute] errorInfo = " . print_r($sth->errorInfo(), true);
Run Code Online (Sandbox Code Playgroud)
PHP版本5.3.15,PHP Postgres客户端版本9.1.4,Postgres服务器版本9.2.1.