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()可以正确处理。