我试图使用oci_bind_by_name将php变量绑定到sql语句中,但它不起作用,这是我的代码
$keyword="'%test%'";
$stmt=oci_parse($connection,"SELECT *
FROM tableName where id=:id and (dataDetails like :key1 or textData like :key1 or name like :key1) and lang = :lang ");
oci_bind_by_name($stmt, ':id', $id);
oci_bind_by_name($stmt, ':key1', $keyword);
oci_bind_by_name($stmt, ':lang', $lang);
oci_execute($stmt, OCI_DEFAULT);
获取$ stmt后,它给了我noth。怎么了?有什么帮助吗?
答案 0 :(得分:2)
您需要在没有单引号的情况下绑定您的值,然后连接您的绑定值以进行类似的比较:
$keyword="test";
$stmt=oci_parse($connection,"SELECT *
FROM tableName where id=:id and (dataDetails like '%' || :key1 || '%' or textData like '%' || :key1 || '%' or name like '%' || :key1 || '%') and lang = :lang ");
oci_bind_by_name($stmt, ':id', $id);
oci_bind_by_name($stmt, ':key1', $keyword);
oci_bind_by_name($stmt, ':lang', $lang);
oci_execute($stmt, OCI_DEFAULT);