[英]Using oci_parse and oci_execute
I'm sure this is something very basic but I can't seem to find my error.我确定这是非常基本的东西,但我似乎找不到我的错误。
I'm trying to execute the following...我正在尝试执行以下...
$c = db_connect();
$email = addslashes($email);
$sql = "SELECT * FROM RUSER WHERE email LIKE '" . $email . "';";
$query = oci_parse($c, $sql) or die(oci_error($c));
$response = oci_execute($query) or die(oci_error($c));
but I get oci8 statement Warning: oci_execute(): ORA-00911: invalid character in /path/to/file.php on line 67
where line 67 is where $response
is assigned.但我得到
oci8 statement Warning: oci_execute(): ORA-00911: invalid character in /path/to/file.php on line 67
where line 67 is where $response
is分配。
So that means there is something wrong with $query
right?所以这意味着
$query
有问题,对吗? But I can't seem to find what that would be.但我似乎无法找到那会是什么。 The raw sql executes fine from the command line.
原始 sql 从命令行执行得很好。 echoing
get_resource_type($query)
gives a resource id... get_resource_type($query)
给出了一个资源 ID...
What am I doing wrong?我究竟做错了什么?
Do NOT include the ;
不要包括
;
in your SQL.在您的 SQL 中。 The
;
;
is not part of SQL itself, its used by various SQL clients (eg sql*plus) as a delimiter to mark the end of commands to be sent to the server.不是 SQL 本身的一部分,它被各种 SQL 客户端(例如 sql*plus)用作分隔符来标记要发送到服务器的命令的结束。
The first error is第一个错误是
$c = oci_connect("user","password","host/dbname") // db_connect() is not true
second error is there should not be ";"第二个错误是不应该有“;” in the statement
在声明中
$sql = "SELECT * FROM RUSER WHERE email LIKE '" . $email . "';";
it should be它应该是
$sql = "SELECT * FROM RUSER WHERE email LIKE '" . $email . "'";
if you want to compare better user "=" than LIKE如果你想比较更好的用户“=”而不是 LIKE
Yes, the semicolon is an issue, but not the only one.是的,分号是一个问题,但不是唯一的问题。
%
, _
) in your value.%
、 _
),则不需要 LIKE 比较。 Suggested Code:建议代码:
$stmt = oci_parse($conn, "SELECT * FROM RUSER WHERE email = :email");
oci_bind_by_name($stmt, ":email", $email);
oci_execute($stmt);
$count = oci_fetch_all($stmt, $resultSet, 0, -1, OCI_FETCHSTATEMENT_BY_ROW);
// hypothetical outputs:
// $count = 1
// $resultSet = [['id => 3, 'email' => 'example@example.com', ...]]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.