API Laravel - 使用 OCI8 或 PDO 使用 IN 和 OUT 参数调用存储过程
API Laravel - Call Store Procedure with IN and OUT parameter using OCI8 or PDO
我是 Laravel 8 的新人。
从 Laravel 连接到 Oracle SQL 开发人员:yajra/oci8
我想使用 API Laravel.
在 oracle 数据库中调用我的存储过程
我的存储过程有 3 个 IN 参数和 4 个 OUT 参数。
我没有什么解决办法,但没有奏效。 (在邮递员中测试)
这是我在 API 中的代码:
(我的解决方案 1 和 2,基于:https://yajrabox.com/docs/laravel-oci8/master/stored-procedure)
我的解决方案 1:
public function checkLogin01(Request $request) {
$procedureName = 'myschema.VERIFY_LOGIN';
$pIsSuccess = "";
$pMsg = "";
$pLastScope = "";
$pParam = "";
$bindings = [
'pUserLogin' => $request['userLogin'],
'pUserPassword' => $request['passLogin'],
'pIPLogin' => $request['userLogin'],
'pIsSuccess' => $pIsSuccess,
'pMsg' => $pMsg,
'pLastScope' => $pLastScope,
'pParam' => $pParam,
];
$result = DB::executeProcedure($procedureName, $bindings);
return response()->json([
'bindings' => $bindings,
'IsSuccess' => $pIsSuccess,
'Msg' => $pMsg,
'LastScope' => $pLastScope,
'Param' => $pParam,
], 422);
}
来自解决方案 1 的错误消息:
"message": "Error Code : 6502\nError Message : ORA-06502: PL/SQL: numeric or value error: character string buffer too small\nORA-06512: at "myschema.VERIFY_LOGIN", line 88\nORA-06502: PL/SQL: numeric or value error: character string buffer too small\nORA-06512: at line 1\nPosition : 0\nStatement : begin myschema.VERIFY_LOGIN(:pUserLogin,:pUserPassword,:pIPLogin,:pIsSuccess,:pMsg,:pLastScope,:pParam); end;\nBindings : [hadi,pass1234,hadi,,,,]\n",
"exception": "Yajra\Pdo\Oci8\Exceptions\Oci8Exception",
我的解决方案 2:
public function checkLogin02(Request $request) {
$pdo = DB::getPdo();
$pIsSuccess = "";
$pMsg = "";
$pLastScope = "";
$pParam = "";
$procedureName = 'myschema.VERIFY_LOGIN';
$stmt = $pdo->prepare("begin " . $procedureName . " (:pUserLogin, :pUserPassword, :pIPLogin, :pIsSuccess, :pMsg, :pLastScope, :pParam); end;");
$stmt->bindParam(':pUserLogin', $request['userLogin'], PDO::PARAM_STR); // this is line 208 from error message
$stmt->bindParam(':pUserPassword', $request['passLogin'], PDO::PARAM_STR);
$stmt->bindParam(':pIPLogin', $request['userLogin'], PDO::PARAM_STR);
$stmt->bindParam(':pIsSuccess', $pIsSuccess, PDO::PARAM_STR|PDO::PARAM_INPUT_OUTPUT, 4000);
$stmt->bindParam(':pMsg', $pMsg, PDO::PARAM_STR|PDO::PARAM_INPUT_OUTPUT, 4000);
$stmt->bindParam(':pLastScope', $pLastScope, PDO::PARAM_STR|PDO::PARAM_INPUT_OUTPUT, 4000);
$stmt->bindParam(':pParam', $pParam, PDO::PARAM_STR|PDO::PARAM_INPUT_OUTPUT, 4000);
$stmt->execute();
return response()->json([
'bindings' => $bindings,
'IsSuccess' => $pIsSuccess,
'Msg' => $pMsg,
'LastScope' => $pLastScope,
'Param' => $pParam,
], 422);
}
来自解决方案 2 的错误消息:
"message": "Indirect modification of overloaded element of Illuminate\Http\Request has no effect",
"exception": "ErrorException",
"file": "/opt/lampp/htdocs/Hadi/projectname/app/Http/Controllers/AuthController.php",
"line": 208,
我的解决方案 3:
public function checkLogin03(Request $request) {
$pdo = DB::getPdo();
$pIsSuccess = "";
$pMsg = "";
$pLastScope = "";
$pParam = "";
$procedureName = 'myschema.VERIFY_LOGIN';
DB::statement("call " . $procedureName . "(:pUserLogin, :pUserPassword, :pIPLogin, :pIsSuccess, :pMsg, :pLastScope, :pParam)" , [
':pUserLogin' => $request['userLogin'],
':pUserPassword' => $request['passLogin'],
':pIPLogin' => $request['userLogin'],
':pIsSuccess' => $pIsSuccess,
':pMsg' => $pMsg,
':pLastScope' => $pLastScope,
':pParam' => $pParam
]);
return response()->json([
'bindings' => $bindings,
'IsSuccess' => $pIsSuccess,
'Msg' => $pMsg,
'LastScope' => $pLastScope,
'Param' => $pParam,
], 422);
}
来自解决方案 3 的错误消息:
"message": "Error Code : 6502\nError Message : ORA-06502: PL/SQL: numeric or value error: character string buffer too small\nORA-06512: at "myschema.VERIFY_LOGIN", line 89\nORA-06502: PL/SQL: numeric or value error: character string buffer too small\nPosition : 5\nStatement : call myschema.VERIFY_LOGIN(:pUserLogin, :pUserPassword, :pIPLogin, :pIsSuccess, :pMsg, :pLastScope, :pParam)\nBindings : [hadi,pass1234*,hadi,,,,]\n (SQL: call myschema.VERIFY_LOGIN(:pUserLogin, :pUserPassword, :pIPLogin, :pIsSuccess, :pMsg, :pLastScope, :pParam))",
"exception": "Illuminate\Database\QueryException",
"file": "/opt/lampp/htdocs/Hadi/projectname/vendor/laravel/framework/src/Illuminate/Database/Connection.php",
"line": 712,
请帮我解决一下。非常感谢!
我放弃了 Eloquent 并求助于香草 PDO 解决方案,它可以正常工作。
public function cekLogin(Request $request) {
$pdo = DB::getPdo();
$pIsSuccess = "";
$pMsg = "";
$pLastScope = "";
$pParam = "";
$procedureName = 'myschema.VERIFY_LOGIN';
$userLogin = $request['userLogin'];
$passLogin = $request['passLogin'];
$userLogin = $request['userLogin'];
$stmt = $pdo->prepare("begin " . $procedureName . " (:pUserLogin, :pUserPassword, :pIPLogin, :pIsSuccess, :pMsg, :pLastScope, :pParam); end;");
$stmt->bindParam(':pUserLogin', $userLogin, PDO::PARAM_STR);
$stmt->bindParam(':pUserPassword', $passLogin, PDO::PARAM_STR);
$stmt->bindParam(':pIPLogin', $userLogin, PDO::PARAM_STR);
$stmt->bindParam(':pIsSuccess', $pIsSuccess, PDO::PARAM_STR|PDO::PARAM_INPUT_OUTPUT, 4000);
$stmt->bindParam(':pMsg', $pMsg, PDO::PARAM_STR|PDO::PARAM_INPUT_OUTPUT, 4000);
$stmt->bindParam(':pLastScope', $pLastScope, PDO::PARAM_STR|PDO::PARAM_INPUT_OUTPUT, 4000);
$stmt->bindParam(':pParam', $pParam, PDO::PARAM_STR|PDO::PARAM_INPUT_OUTPUT, 4000);
$stmt->execute();
return response()->json([
'IsSuccess' => $pIsSuccess,
'Msg' => $pMsg,
'LastScope' => $pLastScope,
'Param' => $pParam,
], 422);
}
我是 Laravel 8 的新人。
从 Laravel 连接到 Oracle SQL 开发人员:yajra/oci8
我想使用 API Laravel.
在 oracle 数据库中调用我的存储过程
我的存储过程有 3 个 IN 参数和 4 个 OUT 参数。
我没有什么解决办法,但没有奏效。 (在邮递员中测试)
这是我在 API 中的代码: (我的解决方案 1 和 2,基于:https://yajrabox.com/docs/laravel-oci8/master/stored-procedure)
我的解决方案 1:
public function checkLogin01(Request $request) {
$procedureName = 'myschema.VERIFY_LOGIN';
$pIsSuccess = "";
$pMsg = "";
$pLastScope = "";
$pParam = "";
$bindings = [
'pUserLogin' => $request['userLogin'],
'pUserPassword' => $request['passLogin'],
'pIPLogin' => $request['userLogin'],
'pIsSuccess' => $pIsSuccess,
'pMsg' => $pMsg,
'pLastScope' => $pLastScope,
'pParam' => $pParam,
];
$result = DB::executeProcedure($procedureName, $bindings);
return response()->json([
'bindings' => $bindings,
'IsSuccess' => $pIsSuccess,
'Msg' => $pMsg,
'LastScope' => $pLastScope,
'Param' => $pParam,
], 422);
}
来自解决方案 1 的错误消息:
"message": "Error Code : 6502\nError Message : ORA-06502: PL/SQL: numeric or value error: character string buffer too small\nORA-06512: at "myschema.VERIFY_LOGIN", line 88\nORA-06502: PL/SQL: numeric or value error: character string buffer too small\nORA-06512: at line 1\nPosition : 0\nStatement : begin myschema.VERIFY_LOGIN(:pUserLogin,:pUserPassword,:pIPLogin,:pIsSuccess,:pMsg,:pLastScope,:pParam); end;\nBindings : [hadi,pass1234,hadi,,,,]\n", "exception": "Yajra\Pdo\Oci8\Exceptions\Oci8Exception",
我的解决方案 2:
public function checkLogin02(Request $request) {
$pdo = DB::getPdo();
$pIsSuccess = "";
$pMsg = "";
$pLastScope = "";
$pParam = "";
$procedureName = 'myschema.VERIFY_LOGIN';
$stmt = $pdo->prepare("begin " . $procedureName . " (:pUserLogin, :pUserPassword, :pIPLogin, :pIsSuccess, :pMsg, :pLastScope, :pParam); end;");
$stmt->bindParam(':pUserLogin', $request['userLogin'], PDO::PARAM_STR); // this is line 208 from error message
$stmt->bindParam(':pUserPassword', $request['passLogin'], PDO::PARAM_STR);
$stmt->bindParam(':pIPLogin', $request['userLogin'], PDO::PARAM_STR);
$stmt->bindParam(':pIsSuccess', $pIsSuccess, PDO::PARAM_STR|PDO::PARAM_INPUT_OUTPUT, 4000);
$stmt->bindParam(':pMsg', $pMsg, PDO::PARAM_STR|PDO::PARAM_INPUT_OUTPUT, 4000);
$stmt->bindParam(':pLastScope', $pLastScope, PDO::PARAM_STR|PDO::PARAM_INPUT_OUTPUT, 4000);
$stmt->bindParam(':pParam', $pParam, PDO::PARAM_STR|PDO::PARAM_INPUT_OUTPUT, 4000);
$stmt->execute();
return response()->json([
'bindings' => $bindings,
'IsSuccess' => $pIsSuccess,
'Msg' => $pMsg,
'LastScope' => $pLastScope,
'Param' => $pParam,
], 422);
}
来自解决方案 2 的错误消息:
"message": "Indirect modification of overloaded element of Illuminate\Http\Request has no effect", "exception": "ErrorException", "file": "/opt/lampp/htdocs/Hadi/projectname/app/Http/Controllers/AuthController.php", "line": 208,
我的解决方案 3:
public function checkLogin03(Request $request) {
$pdo = DB::getPdo();
$pIsSuccess = "";
$pMsg = "";
$pLastScope = "";
$pParam = "";
$procedureName = 'myschema.VERIFY_LOGIN';
DB::statement("call " . $procedureName . "(:pUserLogin, :pUserPassword, :pIPLogin, :pIsSuccess, :pMsg, :pLastScope, :pParam)" , [
':pUserLogin' => $request['userLogin'],
':pUserPassword' => $request['passLogin'],
':pIPLogin' => $request['userLogin'],
':pIsSuccess' => $pIsSuccess,
':pMsg' => $pMsg,
':pLastScope' => $pLastScope,
':pParam' => $pParam
]);
return response()->json([
'bindings' => $bindings,
'IsSuccess' => $pIsSuccess,
'Msg' => $pMsg,
'LastScope' => $pLastScope,
'Param' => $pParam,
], 422);
}
来自解决方案 3 的错误消息:
"message": "Error Code : 6502\nError Message : ORA-06502: PL/SQL: numeric or value error: character string buffer too small\nORA-06512: at "myschema.VERIFY_LOGIN", line 89\nORA-06502: PL/SQL: numeric or value error: character string buffer too small\nPosition : 5\nStatement : call myschema.VERIFY_LOGIN(:pUserLogin, :pUserPassword, :pIPLogin, :pIsSuccess, :pMsg, :pLastScope, :pParam)\nBindings : [hadi,pass1234*,hadi,,,,]\n (SQL: call myschema.VERIFY_LOGIN(:pUserLogin, :pUserPassword, :pIPLogin, :pIsSuccess, :pMsg, :pLastScope, :pParam))", "exception": "Illuminate\Database\QueryException", "file": "/opt/lampp/htdocs/Hadi/projectname/vendor/laravel/framework/src/Illuminate/Database/Connection.php", "line": 712,
请帮我解决一下。非常感谢!
我放弃了 Eloquent 并求助于香草 PDO 解决方案,它可以正常工作。
public function cekLogin(Request $request) {
$pdo = DB::getPdo();
$pIsSuccess = "";
$pMsg = "";
$pLastScope = "";
$pParam = "";
$procedureName = 'myschema.VERIFY_LOGIN';
$userLogin = $request['userLogin'];
$passLogin = $request['passLogin'];
$userLogin = $request['userLogin'];
$stmt = $pdo->prepare("begin " . $procedureName . " (:pUserLogin, :pUserPassword, :pIPLogin, :pIsSuccess, :pMsg, :pLastScope, :pParam); end;");
$stmt->bindParam(':pUserLogin', $userLogin, PDO::PARAM_STR);
$stmt->bindParam(':pUserPassword', $passLogin, PDO::PARAM_STR);
$stmt->bindParam(':pIPLogin', $userLogin, PDO::PARAM_STR);
$stmt->bindParam(':pIsSuccess', $pIsSuccess, PDO::PARAM_STR|PDO::PARAM_INPUT_OUTPUT, 4000);
$stmt->bindParam(':pMsg', $pMsg, PDO::PARAM_STR|PDO::PARAM_INPUT_OUTPUT, 4000);
$stmt->bindParam(':pLastScope', $pLastScope, PDO::PARAM_STR|PDO::PARAM_INPUT_OUTPUT, 4000);
$stmt->bindParam(':pParam', $pParam, PDO::PARAM_STR|PDO::PARAM_INPUT_OUTPUT, 4000);
$stmt->execute();
return response()->json([
'IsSuccess' => $pIsSuccess,
'Msg' => $pMsg,
'LastScope' => $pLastScope,
'Param' => $pParam,
], 422);
}