使用 PDO 的服务器端数据表
Server Side Datatables using PDO
我将缩短从服务器获取的 PHP。我正在使用 SSP 助手 class 文件:
//rest of code up here
require( 'ssp.class.php' );
echo json_encode(
SSP::complex( $_GET, $sql_details, $table, $primaryKey, $columns, $where, "business_name != 'xyzcompany'")
);
这很好用。
但是,我想根据用户输入动态替换 'xyzcompany'。为了安全起见,我想使用 PDO。我知道一般如何使用 PDO,但现在我将如何将它折叠到这个数据表示例中。我读过 SSP 助手处理 PDO,但我找不到有关如何使用它的文档。例如伪代码:
//rest of code up here
require( 'ssp.class.php' );
$business_name = $_POST['biz']; //supplied by user in text input
:biz_name = $business_name; //I know this isn't correct syntax
echo json_encode(
SSP::complex( $_GET, $sql_details, $table, $primaryKey, $columns, $where, "business_name != :biz_name")
);
使用下面的代码:
# Obtain an PHP PDO connection from a connection details array
$db = SSP::db($sql_details);
echo json_encode(
SSP::complex($_GET, $sql_details, $table, $primaryKey, $columns, $where, "business_name != ".$db->quote($business_name))
);
我将缩短从服务器获取的 PHP。我正在使用 SSP 助手 class 文件:
//rest of code up here
require( 'ssp.class.php' );
echo json_encode(
SSP::complex( $_GET, $sql_details, $table, $primaryKey, $columns, $where, "business_name != 'xyzcompany'")
);
这很好用。
但是,我想根据用户输入动态替换 'xyzcompany'。为了安全起见,我想使用 PDO。我知道一般如何使用 PDO,但现在我将如何将它折叠到这个数据表示例中。我读过 SSP 助手处理 PDO,但我找不到有关如何使用它的文档。例如伪代码:
//rest of code up here
require( 'ssp.class.php' );
$business_name = $_POST['biz']; //supplied by user in text input
:biz_name = $business_name; //I know this isn't correct syntax
echo json_encode(
SSP::complex( $_GET, $sql_details, $table, $primaryKey, $columns, $where, "business_name != :biz_name")
);
使用下面的代码:
# Obtain an PHP PDO connection from a connection details array
$db = SSP::db($sql_details);
echo json_encode(
SSP::complex($_GET, $sql_details, $table, $primaryKey, $columns, $where, "business_name != ".$db->quote($business_name))
);