Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 当语法正确时,MySQL抛出语法错误_Php_Mysql - Fatal编程技术网

Php 当语法正确时,MySQL抛出语法错误

Php 当语法正确时,MySQL抛出语法错误,php,mysql,Php,Mysql,我有一段代码,可以从数据库表中一次检索10条记录: $query = 'SELECT * FROM shares ORDER BY create_date DESC LIMIT :sharesPerPage OFFSET :lowerBound'; $this->prepare($query); $this->bind(':sharesPerPage', $sharesPerPage); $this->bind(':l

我有一段代码,可以从数据库表中一次检索10条记录:

$query = 'SELECT *
          FROM shares
          ORDER BY create_date DESC
          LIMIT :sharesPerPage OFFSET :lowerBound';
$this->prepare($query);
$this->bind(':sharesPerPage', $sharesPerPage);
$this->bind(':lowerBound', $lowerBound);
$this->execute();
出于某种原因,正在抛出一个PDO异常,其中包含关于“10”偏移量“0”的语法错误的信息,该偏移量分别对应于
$sharesPerPage
$lowerBound


我已经检查了所有内容,但查询结果仍然是错误的。该代码有什么问题?

您必须将值转换为int。否则它将转换为字符串

$this->bind(':sharesPerPage', (int)$sharesPerPage, PDO::PARAM_INT));
$this->bind(':lowerBound', (int)$lowerBound, PDO::PARAM_INT));

您必须将值转换为int。否则它将转换为字符串

$this->bind(':sharesPerPage', (int)$sharesPerPage, PDO::PARAM_INT));
$this->bind(':lowerBound', (int)$lowerBound, PDO::PARAM_INT));