我有一个页面,允许用户按名字搜索人物。到目前为止,我已经尝试了几种方法,包括oci_bind_by_name,但我没有从查询中获得任何结果。这是我目前的代码:
if(isset($_GET['FirstName_Search'])){
$stid_check = oci_parse($conn, 'SELECT ID,UserName,Prefix,FirstName,LastName,Suffix,Title,Phone,Email,Department FROM WCM_People WHERE FirstName LIKE '%$FirstName%' ORDER BY LastName,FirstName');
// bind values to the parameters in the parsed sql string
//oci_bind_by_name($stid_check, ":FirstName", $FirstName);
//oci_bind_by_name($stid_check, ":LastName", $LastName);
$r = oci_execute($stid_check);
while ($row = oci_fetch_array($stid_check, OCI_ASSOC+OCI_RETURN_NULLS)) {
echo "<tr>";
foreach ($row as $item) {
echo "<td>" . $item . "</td> \n";
}
echo "</tr>";
}
// free the sql statement when finished
oci_free_statement($stid_check);
}
以下是随之而来的警告和错误:
Warning: Division by zero
Warning: oci_fetch_array(): ORA-24338: statement handle not executed
它说ORA-24338错误来自这一行:
while ($row = oci_fetch_array($stid_check, OCI_ASSOC+OCI_RETURN_NULLS)) {
答案 0 :(得分:0)
根据OP关于提出问题的请求。
使用双引号更改您的查询:
($conn, "SELECT ID,... LIKE '%$FirstName%' ORDER BY LastName,FirstName")
在将查询包装在单引号内时,您使用单引号作为搜索查询,这些引号将无法正确呈现,并会反过来生成错误。