SQL LIMIT不适用于define

时间:2015-12-04 08:35:15

标签: php sql limit sql-limit

我正在用PHP编写SQL请求。请求工作正常如下:

$testQuery = "SELECT `title` FROM `bibliography` Where title LIKE '%$search%'";

我需要添加一个限制。如果我添加一个带数字的LIMIT,它可以正常工作:

$testQuery = "SELECT `title` FROM `bibliography` Where title LIKE '%$search%' LIMIT 5";

但如果我使用define:

define( 'PAGING', 2 );
$testQuery = "SELECT `title` FROM `bibliography` Where title LIKE '%$search%' LIMIT PAGING";

它会抛出错误:

  

未声明的变量:PAGING SQL = SELECT title FROM bibliography   标题LIKE' %%'极限寻找

然而,在代码的其他部分,PAGING工作正常。为什么这不起作用,我如何使用定义来限制?

1 个答案:

答案 0 :(得分:0)

你能在这样的查询中传递一个变量而不是常量吗? (或必须保持不变)

$define = 5;
$testQuery = "SELECT `title` FROM `bibliography` Where title LIKE '%$search%' LIMIT $define";