我有一个follows(AFAIK,PDO statement,因为PDO statement不需要数据作为escaped进行准备):
$insert = "INSERT INTO `errors`(`code`,`number`,`title`,`message`) VALUES( :code, :num, :title, :err )";
$arr = Array(
Array( ':code', $_POST['code'], 'PDO::PARAM_STR' ),
Array( ':num', $_POST['number'], 'PDO::PARAM_INT' ),
Array( ':title', $_POST['title'], 'PDO::PARAM_STR' ),
Array( ':err', htmlentities( str_replace("\n", "<br />", $_POST['error']), ENT_HTML5, 'UTF-8' ), 'PDO::PARAM_STR' )
);
$stmt = $conn->prepare($insert);
foreach( $arr as $a ) {
$stmt->bindValue( $a[0], $a[1], $a[2] );
}
$stmt->execute();
$stmt->debugDumpParams();这段代码什么也不做。但它确实生成了这样一个转储:
SQL: [91] INSERT INTO `errors`(`code`,`number`,`title`,`message`) VALUES( :code, :num, :title, :err )
Params: 0发布于 2012-10-01 15:08:56
绑定参数的类型信息是constant,而不是字符串。
Array( ':code', $_POST['code'], PDO::PARAM_STR )
// ^ ^ no quotes更新
数组应该如下所示:
$arr = Array(
Array( ':code', $_POST['code'], PDO::PARAM_STR ),
Array( ':num', $_POST['number'], PDO::PARAM_INT ),
Array( ':title', $_POST['title'], PDO::PARAM_STR ),
Array( ':err', htmlentities( str_replace("\n", "<br />", $_POST['error']), ENT_HTML5, 'UTF-8' ), PDO::PARAM_STR )
);https://stackoverflow.com/questions/12675914
复制相似问题