PHP - MySQLi 准备语句:未知 "max" 函数(错误 1630)
PHP - MySQLi Prepared Statement: unknown "max" function (Error 1630)
我在准备要在我的数据库上查询的简单语句时遇到错误。这是一个非常简单的。据称函数 max()
不存在。这是简单的查询:
SELECT coalesce ( max ( p_order ), 0 ) + 1 AS new FROM pages
它没有要绑定的参数(但我使用自己的 class 来管理我的查询,因此始终使用准备好的语句)。
准备语句时,我从数据库中收到以下错误:"FUNCTION fa_cms.max does not exist. Check the 'Function Name Parsing and Resolution' section in the Reference Manual"。代码是 1630.
我可以直接在数据库 (MariaDB 10.1.29) 上执行此查询,没有任何问题 - 并得到“1”,因为 table 仍然是空的。
但是当我通过自己的 PHP class 调用这个语句时,我得到了这个错误。所有其他语句的准备和执行都没有任何问题 - 有或没有参数。
max()
聚合函数有什么特别之处吗?
问题是 max
和 (
之间的 space。来自 documentation:
By default, there must be no whitespace between a function name and the parenthesis following it. This helps the MySQL parser distinguish between function calls and references to tables or columns that happen to have the same name as a function.
不过,此要求似乎并未始终如一地执行。似乎只有在使用聚合函数时才真正重要。
因此将您的查询更改为:
SELECT coalesce(max(p_order), 0) + 1 AS new FROM pages
我在准备要在我的数据库上查询的简单语句时遇到错误。这是一个非常简单的。据称函数 max()
不存在。这是简单的查询:
SELECT coalesce ( max ( p_order ), 0 ) + 1 AS new FROM pages
它没有要绑定的参数(但我使用自己的 class 来管理我的查询,因此始终使用准备好的语句)。
准备语句时,我从数据库中收到以下错误:"FUNCTION fa_cms.max does not exist. Check the 'Function Name Parsing and Resolution' section in the Reference Manual"。代码是 1630.
我可以直接在数据库 (MariaDB 10.1.29) 上执行此查询,没有任何问题 - 并得到“1”,因为 table 仍然是空的。
但是当我通过自己的 PHP class 调用这个语句时,我得到了这个错误。所有其他语句的准备和执行都没有任何问题 - 有或没有参数。
max()
聚合函数有什么特别之处吗?
问题是 max
和 (
之间的 space。来自 documentation:
By default, there must be no whitespace between a function name and the parenthesis following it. This helps the MySQL parser distinguish between function calls and references to tables or columns that happen to have the same name as a function.
不过,此要求似乎并未始终如一地执行。似乎只有在使用聚合函数时才真正重要。
因此将您的查询更改为:
SELECT coalesce(max(p_order), 0) + 1 AS new FROM pages