PHP PDO撇号

use*_*365 2 php pdo apostrophe

我有一个问题从PHP执行存储过程(FIREBIRD):

$sqlSP="select record_created,record_updated from SP_IMPORT_CRM_SELECTIE (11, 'AC015612','".$tester."'..............
Run Code Online (Sandbox Code Playgroud)

当$ tester包含这个符号'我有问题..

我该如何解决这个问题?

Dav*_*Boy 11

实质上,您需要在查询中使用它之前转义字符串.

最好的方法是使用PDO准备的语句:

$sqlSP="select record_created,record_updated from SP_IMPORT_CRM_SELECTIE (11, 'AC015612',:tester)";
$ps=$dbhandle->prepare($sqlSP);
$ps->bindParam(':tester',$tester,PDO::PARAM_STR);
$ps->execute();
Run Code Online (Sandbox Code Playgroud)

(假设这$dbhandle是你的PDO对象)