pdo 错误 php,多语句查询中的PHP PDO错误
我在我的一個實時網絡應用程序中遇到了這個問題.看來如果你通過PHP PDO向MysqL發出一個多語句查詢,并且第一個語句是一個insert語句,而第二個語句是一個update語句,那么PDO :: nextRowset()函數不會返回正確的數字結果集(請注意,自PHP 5.3起,PDO應該支持每個MySQL查詢的多個語句.)
這是一個例子:
create database `test`character set utf8 collate utf8_general_ci;
create table `test`.`testtable`( `id` int );
PHP
$link = new \PDO('MysqL:host=localhost;dbname=test','username','password');
//Run one of the 4 $handle assignments at a time (comment out all but one).
//Run #4 on an empty table to compare the results of #1 and #4.
//WORKS: INSERT,followed by SELECT,followed UPDATE
//Output:
//Rowset 1
//Rowset 2
//Results detected
$handle = $link->prepare(' insert into testtable(id) values(1);
select * from testtable where id = ?;
update testtable set id = 2 where id = ?;');
//WORKS: SELECT,followed by UPDATE
//Output:
//Rowset 1
//Results detected
$handle = $link->prepare('select * from testtable where id = ?;
update testtable set id = 2 where id = ?;');
//WORKS: UPDATE,followed by SELECT
//Output:
//Rowset 1
//Rowset 2
//Results detected
$handle = $link->prepare('select * from testtable where id = ?;
update testtable set id = 2 where id = ?;');
//DOESN'T WORK: INSERT,followed by UPDATE,followed by SELECT
//Output:
//Rowset 1
//Expected output: same as examples 1 and 3
$handle = $link->prepare('insert into testtable(id) values(1);
update testtable set id = 2 where id = ?;
select * from testtable where id = ?;');
$handle->bindValue('1','1');
$handle->bindValue('2','2');
$handle->execute();
$i = 1;
do{
print('Rowset ' . $i++ . "\n");
if($handle->columnCount() > 0)
print("Results detected\n");
}while($handle->nextRowset());
?>
有沒有人知道我做錯了什么?為什么我不能把我的選擇聲明放在最后?
PHP 5.3.5
MysqL 5.1.54
總結
以上是生活随笔為你收集整理的pdo 错误 php,多语句查询中的PHP PDO错误的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux resin 查看日志命令,【
- 下一篇: php怎么排除空的数组,【技术产品】ph