Home  >  Article  >  Backend Development  >  PDO:exec()返回值的有关问题

PDO:exec()返回值的有关问题

WBOY
WBOYOriginal
2016-06-13 13:36:501309browse

PDO::exec()返回值的问题。
//设置脚本运行时间为不限制
set_time_limit(0);

//用PDO创建pgsql连接
try {
$pgLink = new PDO('pgsql:host=localhost port=5432 dbname=db2 user=root password=111111');
}catch(Exception $e) {
echo $e->getMessage();
}

//定义SQL修改语句
$sql = "UPDATE trade.membership SET gender=1, birth_type=0, name='wsy', birthday='2011-01-01', email='', join_date='2011-01-02', status=1, address='aaaa',id_number='25454', postcode='100031', phone='666', type_id=1 WHERE mobile='110';";

//执行SQL语句
$result = $pgLink->exec($sql);

//输出SQL结果
echo $result.'  '.$sql;

输出结果:
1 UPDATE trade.membership SET gender=1, birth_type=0, name='wsy', birthday='2011-01-01', email='', join_date='2011-01-02', status=1, address='aaaa', id_number='25454', postcode='100031', phone='666', type_id=1 WHERE mobile='110';

问题是这样:
这个表里压根就没有mobile='110'这一行,将$sql语句拿到本地SQL服务器上运行也是“0条影响行数”。
但在程序里的结果为什么是“1”?PDO::exec()的输出结果不应该是增删改的受影响行数吗?

------解决方案--------------------
这个应该是PDO的一个BUG,用预处理做然后用PDO::rowCount()可以正确处理。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn