我正在尝试从PHP调用Oracle存储过程。我有两个HTML文本框。用户在这些文本框中提供用户名和密码。单击按钮后,这些值将传递到PHP中。 PHP应该将这些参数传递给Oracle存储过程。这两个参数都已成功传递到PHP。但是在运行Procedure时,它将引发错误。尝试在SQL Developer上运行相同的过程时,它运行良好。
我尝试遵循以下文档- Call Oracle stored procedure from PHP
https://www.sitepoint.com/community/t/php-and-oracle-oci8-stored-procedures/7541
Oracle过程-
create or replace
PROCEDURE proc_create_user (
p_user_name IN VARCHAR2,
p_user_pass IN VARCHAR2)
AUTHID DEFINER
IS
lv_user_exists INTEGER := 0;
lv_user_name VARCHAR2 (15) := UPPER (trim(p_user_name));
BEGIN
SELECT COUNT (*)
INTO lv_user_exists
FROM dba_users
WHERE username = lv_user_name;
IF lv_user_exists = 0
THEN
EXECUTE IMMEDIATE
'CREATE USER '
|| lv_user_name
|| ' IDENTIFIED BY '
|| p_user_pass
|| ' DEFAULT TABLESPACE USERS TEMPORARY TABLESPACE TEMP PROFILE DEFAULT ACCOUNT UNLOCK';
EXECUTE IMMEDIATE 'GRANT CONNECT TO ' || lv_user_name;
EXECUTE IMMEDIATE 'ALTER USER ' || p_user_name || ' DEFAULT ROLE ALL';
ELSE
RAISE_APPLICATION_ERROR (-20000, 'User already exists');
END IF;
END proc_create_user;
PHP代码-
<?php
// required headers
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
header("Access-Control-Allow-Methods: POST");
header("Access-Control-Max-Age: 3600");
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require '../vendor/autoload.php';
foreach($_GET as $key=>$value){
}
$uid = $_GET['uid'];
$pass = $_GET['pass'];
$uidupper = strtoupper($_GET['uid']);
$uidupper = "'".$uidupper."'";
$pass = "'".$pass."'";
echo $uidupper;
echo $pass;
$db = "(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=ppe.testdom.com)(PORT=1521)(SEND_BUF_SIZE=)(RECV_BUF_SIZE=))(LOAD_BALANCE=yes))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=ppe.testdom.com)))" ;
$conn = OCILogon("test", "test", $db);
$sql = 'BEGIN PROC_CREATE_USER(:p_user_name, :p_user_pass); END;';
$stmt = oci_parse($conn,$sql);
oci_bind_by_name($stmt,":p_user_name",$uidupper);
oci_bind_by_name($stmt,":p_user_pass",$pass);
echo $sql;
echo $stmt;
oci_execute($stmt);
?>
错误详细信息-
'ADB''abcd@1234'BEGIN DWABI.PROC_CREATE_USER(:p_user_name, :p_user_pass); END;Resource id #79<br />
<b>Warning</b>: oci_execute(): ORA-01935: missing user or role name
ORA-06512: at "DWABI.PROC_CREATE_USER", line 16
ORA-06512: at line 1 in <b>C:\xampp\htdocs\Log_Check\email_db.php</b> on line <b>48</b><br />
如果有人能让我知道我在做什么错,这将非常有帮助。
更新: 已通过添加双引号(而不是单引号)解决了该问题。