我正在尝试使用两个表完成内部联接(Oracle称之为equijoins)并且我只是遗漏了一些东西,因为它与MySQL内部联接不同。我也是PHP的新手(来自Lasso)所以我正在努力严格要求我的语法以保证自己的理智。我查看了有关此错误的所有其他帖子,但他们没有帮助。
使用PHP 5.5.29连接到Oracle 12c数据库,在php信息页面安装并验证了OCI8。
Oracle's explanation of inner joins
$ login是纯文本,$ pw在此代码段之前进行哈希处理:
// separate the login types by the "_" character
if (strpos($login, "_") == true) {
$fieldname = 'web_password_hash';
$dynfield = 'web_id';
$dynfield1 = 's.web_id';
} else {
$fieldname = 'student_web_password_hash';
$dynfield = 'student_web_id';
$dynfield1 = 's.student_web_id';
}
$schoolid = '(pcs.schoolid=4 OR pcs.schoolid=5)';
// search custom table for a field with the correct password (parent/student)
$dbc = oci_connect($psusername, $pspassword, $psconnection);
if(!$dbc) {
echo "Oracle Not connected";
} else {
$stmt = oci_parse($dbc, 'SELECT pcs.student_number AS snumber, :dynfield1 AS loginid, s.ID AS sid, s.family_ident AS famid, s.firstname AS fname, s.last_name AS lname, s.grade_level AS gradelevel
FROM pvsis_custom_students pcs, students s
WHERE pcs.student_number=s.student_number
AND :schoolid
AND pcs.field_name=:fieldname
AND pcs.string_value=:pw
AND s.enroll_status=0;');
// bind parameters to prevent SQL injection
oci_bind_by_name($stmt, ':dynfield1', $dynfield1);
oci_bind_by_name($stmt, ':fieldname', $fieldname);
oci_bind_by_name($stmt, ':schoolid', $schoolid);
oci_bind_by_name($stmt, ':pw', $pw);
// execute statement
oci_execute($stmt);
我得到的错误是:警告: oci_execute():ORA-00920: / path / to / file line XXX
中的关系运算符无效答案 0 :(得分:1)
您无法按照您在此处的方式绑定字段名称。您需要动态构建查询:
$stmt = oci_parse($dbc, 'SELECT pcs.student_number AS snumber, ' . $dynfield1 . ' AS loginid, s.ID AS sid, s.family_ident AS famid, s.firstname AS fname, s.last_name AS lname, s.grade_level AS gradelevel
FROM pvsis_custom_students pcs, students s
WHERE pcs.student_number=s.student_number
AND ' . $schoolid . '
AND pcs.field_name=' . $fieldname . '
AND pcs.string_value=:pw
AND s.enroll_status=0;');
删除bind_by_name
,:dynfield1
和:fieldname
的{{1}}来电。
祝你好运。