这很可能归结为我对 ssp.class 如何工作的基本误解,尤其是在列定义方面。我不知道“dt”键的作用是什么,除了倒在代码上。我想我可以给它一个列顺序,或者一个字符串,在这种情况下它成为 json 中的键。
另一种可能性是我的 pdo 选项搞砸了,不允许 pdo 连接中的绑定?我可以寻找什么样的配置错误?
另一种可能性,php 7.3.30:它允许以这种方式绑定吗?只是确保。
注意:如果我有任何名称不匹配的列,我更改了一些以至少将它们匿名化。
提前致谢。
我所知道的是,如果我进行全局搜索,我可以看到 $request['search']['value']; 已填充,然后枚举寻找“可搜索”==“真”的列(作为测试,我只包括文本字段),我可以看到在 SQL 中的每个字段上创建了一个 :binding_X 并在绑定数组在那里:bindingX = "%searchphrase%"。我也设置了 $WhereAll,所以 sql 最终是这样的:
SELECT `author_id`, `download_type`, `download_type_text`, `pro_id`, `num_clicks`, `script_title`, `pro_name`, `pro_co`, `pro_addr`, `pro_city`, `pro_state`, `pro_country`, `pro_zip`, `tinyurl`, `share_source`, `link_type`, `original_title`, `dl_id`, `dl_date`, `viewed_by_writer`
FROM `SomeTable`
WHERE (`pro_name` LIKE :binding_0 OR `download_type_text` LIKE :binding_1 OR `script_title` LIKE :binding_2 OR `pro_co` LIKE :binding_3 OR `dl_id` LIKE :binding_4) AND author_id = 'testuser55'
ORDER BY `dl_date` DESC
LIMIT 0, 10
我可以看到有 5 个这样的绑定:
键:":binding_0" val:"%searchphrase%" 类型:2
即使搜索短语是有效的,如果我在 MySQL 中运行它并换出绑定,它当然是正确的。
php 7.3.30 jquery.Datatables 1.10.22 ssp.class.php 的最新版本
表的查询和排序工作正常,除非我尝试使用全局搜索过滤器或列过滤器进行过滤。
数据表(我将其缩短为没有列过滤器的测试版本):
var viewtableType = 'something';
var viewingsTable = $("#viewingsTable").DataTable({
pageLength: 10,
dom: "some dom that works",
serverSide: true,
ajax: {
url: "script_views_data.php",
type: "POST",
data: function (data) {
data.CurrentTable = viewtableType;
},
},
columns: [
{ name: "pro_name", data: "pro_name", title: "Viewed By", orderable: true, searchable: true },
{ name: "download_type_text", data: "download_type_text", title: "Viewed Item", orderable: true, searchable: true},
{ name: "script_title", data: "script_title", title: "Script Title", orderable: true, searchable: true },
{ name: "dl_date", data: "dl_date", title: "Date", orderable: true, searchable: false },
{ data: "pro_id", name: "pro_id", searchable: false, visible: false },
{ data: "pro_co", name: "pro_co", searchable: true, visible: false },
{ data: "pro_addr", name: "pro_addr", searchable: false, visible: false },
{ data: "pro_city", name: "pro_city", searchable: false, visible: false },
{ data: "pro_state", name: "pro_state", searchable: false, visible: false, },
{ data: "pro_zip", name: "pro_zip", searchable: false, visible: false },
{ data: "pro_country", name: "pro_country", searchable: false, visible: false, },
{ data: "dl_id", name: "dl_id", searchable: true, visible: false },
]
}
});
ssp.class 的服务器端脚本包装器(除了删除顶部的建议行之外没有改变):
<?php
session_start();
include "db_stuff.php";
require("varStuff.inc");
require('ssp.class.php');
$current_table = "";
if (isset($_POST['CurrentTable']) && !empty($_POST['CurrentTable'])) {
$current_table = $_POST['CurrentTable'];
} else {
exit("No Current Table was set");
}
if (!isset($_SESSION['Userid'])) {
exit("Not logged in");
}
$WhereAll = "writer_id = '{$_SESSION['Userid']}'";
$WhereResult = "";
if (isset($_POST['ScriptFilterID']) && !empty($_POST['ScriptFilterID'])) {
$WhereResult = "script_reg_id = '{$_POST['ScriptFilterID']}'";
}
$db_view = 'vwSomeView';
$primaryKey = 'dl_id';
$columns = array(
array('db' => 'author_id', 'dt' => 'author_id'),
array('db' => 'download_type', 'dt' => 'download_type'),
array('db' => 'download_type_text', 'dt' => 'download_type_text'),
array('db' => 'pro_id', 'dt' => 'pro_id'),
array('db' => 'num_clicks', 'dt' => 'num_clicks'),
array('db' => 'some_title', 'dt' => 'some_title'),
array('db' => 'pro_name', 'dt' => 'pro_name'),
array('db' => 'pro_co', 'dt' => 'pro_co'),
array('db' => 'pro_addr', 'dt' => 'pro_addr'),
array('db' => 'pro_city', 'dt' => 'pro_city'),
array('db' => 'pro_state', 'dt' => 'pro_state'),
array('db' => 'pro_country', 'dt' => 'pro_country'),
array('db' => 'pro_zip', 'dt' => 'pro_zip'),
array('db' => 'tinyurl', 'dt' => 'tinyurl'),
array('db' => 'share_source', 'dt' => 'share_source'),
array('db' => 'link_type', 'dt' => 'link_type'),
array('db' => 'original_title', 'dt' => 'original_title'),
array('db' => 'dl_id', 'dt' => 'dl_id'),
array(
'db' => 'dl_date',
'dt' => 'dl_date',
'formatter' => function ($d, $row) {
return date('n/j/Y', strtotime($d));
}
),
array(
'db' => 'viewed_by_author',
'dt' => 'viewed_by_author',
'formatter' => function ($d, $row) {
return ($d == null)? "" : date('n/j/Y', strtotime($d));
}
)
);
//Output the json:
echo json_encode(
$resultSet
);