+
82
-

pdo预处理limit出现错误

pdo预处理limit出现错误

我的sql如下

select * from table limit ?,?

然后传值

$stmt = $this->_connection->prepare($_sql);
$stmt->execute($_val);

结果出现这个错误

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''0','12'' at line 1

请问怎么解决?


网友回复

+
1
-

这主要是由于limit 后的两个参数,mysql默认只能传数字类型的值,但是php pdo默认没有设置类型的话会以string的方式传值,这就导致出现了这个错误,可以设置一下

在数据库$pdo这块添加

点击查看剩余70%

我知道答案,我要回答