function fetch($query='', $type = 'both') { $result_type=pdo::fetch_.$type; $query->setfetchmode($result_type);//这报错,$query是pdo的query结果 $result_arr=$query->fetch(); return $result_arr;}
pdostatement::setfetchmode(): sqlstate[hy000]: general error: mode must be an integer
这个是什么问题?本地测试没问题,放空间报错
回复内容: function fetch($query='', $type = 'both') { $result_type=pdo::fetch_.$type; $query->setfetchmode($result_type);//这报错,$query是pdo的query结果 $result_arr=$query->fetch(); return $result_arr;}
pdostatement::setfetchmode(): sqlstate[hy000]: general error: mode must be an integer
这个是什么问题?本地测试没问题,放空间报错
no code, no truth.
你得把代码和数据库从你的项目中抽出来并尽量简化,以便于其它人在自己的电脑上重现你遇到的问题,再来分析。
pdo扩展在windows环境和linux环境的行为不相同,有的代码在windows环境是不报错的(warning、notice全打开也不报),但在linux环境就会报错的,我7年前遇到过。
改一行代码:
$query->setfetchmode(constant($result_type));
pdostatement::setfetchmode方法必须传入第一个int型的mode参数啊,你肯定没传或者传的不是int型的。至于本地测试没报错,可能是service的错误输出级别跟空间的不一样。
pdostatement::setfetchmode ( int $mode );//mode//the fetch mode must be one of the pdo::fetch_* constants.
一个更好的方法,有图有真相:
你理解错文档的意思了,那是要你填一个pdo的常量,不是字符串。