我无法获得使用 mysql 处理服务器端脚本的 where 语句



我正在使用一个where子句进行简单的查询,该子句在具有可访问的名称中查找LIKE。

这是我的结构

$lName = strtoupper($_GET['lname']);

// DB table to use
$table = 'alx80';
// Table's primary key
$primaryKey = 'casnum';
$whereResult = " WHERE  ptynam LIKE '%$lName%' ";
// Array of database columns which should be read and sent back to DataTables.
// The `db` parameter represents the column name in the database, while the`dt`
// parameter represents the DataTables column identifier. In this case simple
// indexes
$columns = array(
array( 'db' => 'casnum', 'dt' => 'casnum' ),
array( 'db' => 'castyp',  'dt' => 'castyp' ),
array( 'db' => 'castds',   'dt' => 'castds' ),
array( 'db' => 'ptynam',     'dt' => 'ptynam' ),
array( 'db' => 'ptytyp',     'dt' => 'ptytyp' ),
array( 'db' => 'istat',     'dt' => 'istat' ),
);
// SQL server connection information
$sql_details = array(
'user' => 'kiju',
'pass' => 'jkiuju$hhg2',
'db'   => 'mysql',
'host' => 'localhost'
);

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* If you just want to use the basic configuration for DataTables with PHP
* server-side, there is no need to edit below this line.
*/
require( '../DataTables-1.10.5/examples/server_side/scripts/ssp.class.php' );
echo json_encode(
    //SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns )
SSP::complex ( $_GET, $sql_details, $table, $primaryKey, $columns, $whereResult )
);

当我运行这个时,我收到此错误

数据表警告:表 id=示例 - 发生 SQL 错误:SQLSTATE[42000]:语法错误或访问冲突:1064 SQL 语法有错误;请查看与您的 MySQL 服务器版本对应的手册,了解在"WHERE ptynam = '%SMITH%' 附近使用的正确语法 按 casnum ASC 订购 限制 0, 100' 在第 3 行

好。

我一直在尝试找到工作地点,所以我使用//SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns, $where ),它工作得很好。除了我无法搜索数据表,因为我已经定义了我的 where 子句。

所以我的问题是,如何将数据表服务器端脚本与 where 子句一起使用,为什么会出现此错误?

其他任何有这个问题的人,当你使用复杂函数时,你必须从$whereResult中取出"WHERE",然后它就可以工作

最新更新