<?php
$current = 0;
$results = 5;
$statement = $db->prepare("SELECT title, id FROM mytable LIMIT ?, ?");
$statement->execute(array($current, $results));
?>
var_dump($statement);
=> public 'queryString' => string 'SELECT title, id FROM mytable LIMIT ?, ?' (length=39)
谁能帮我找出为什么这不起作用?
最佳答案
您需要将这些参数绑定(bind)为整数,而不是字符串(默认)。将参数绑定(bind)为字符串会自动在它们周围添加引号。
$statement->bindParam(":current", $current, PDO::PARAM_INT)
此示例使用命名占位符。我建议你无论如何都使用它。
关于PHP 准备好的语句不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10863368/