我有以下使用此function
执行商店过程的代码$proc->bind_param("i", $eventId_);
if (!$proc->execute())
{
die("Database execution failed. Error: \n" . $proc->error);
}
但我收到错误
Database execution failed. Error: There is no 'db_jamce'@'%' registered
奇怪的是,数据库用户'db_jamce'不在代码库中的任何位置,因此它必须是数据库问题。尽管存储过程试图以不再存在的不同用户身份执行,但它仍然存在。还有其他人以前遇到过这种问题吗?
答案 0 :(得分:1)
通常,您可以执行此类步骤来使用存储过程。检查两个位置的用户,PHP文件和数据库上的SQL过程。
我通常有一个单独的连接过程,但这或多或少是序列的表示
<?php
// initialize variables
$handler = false;
$server = false;
$user = false;
$password = false;
$database = false;
// assign right values for variables. Specially the user that is going to execute the procedure.
// create a handler for this session with the DB
$handler = mysqli_init();
// connect using the right values
$var_to_check_state_of_connection = mysqli_real_connect( $handler, $server, $user, $password, $database );
// not neccessary in your case, but is good practice
mysqli_set_charset( $handler, "utf8" );
// initialize the statement
$var_to_check_state_of_statement = mysqli_stmt_init( $handler );
// prepare the statement for execution
$var_to_check_state_of_prepare = mysqli_stmt_prepare( $handler, "call right_procedure( ? )" );
// bind param
$var_to_check_state_of_binding = mysqli_stmt_bind_param( $handler, 's', $your_variable );
// execute the statement
$var_to_check_state_of_execution = mysqli_stmt_execute( $handler );
?>
你还必须检查程序本身,因为它可能有一个DEFINER设置,如下所示:
CREATE DEFINER = 'user'@'localhost' PROCEDURE `your_procedure`
...
SQL SECURITY DEFINER
安全参数可以是INVOKER。