duanju8308 2014-02-24 23:17
浏览 43
已采纳

MySQL试图以不同的用户身份运行存储过程

I have the following code that is executing a store procedure using this function

$proc->bind_param("i", $eventId_);
if (!$proc->execute())
{
    die("Database execution failed. Error: 
" . $proc->error);
}

But I am getting an error

Database execution failed. Error: There is no 'db_jamce'@'%' registered

What's strange is that the the database user 'db_jamce' isn't anywhere in the codebase so it must be a database issue. It's asthough the store procedure is trying to be executing as a different user that no longer exists. Has anyone else had this kind of problem before?

  • 写回答

1条回答 默认 最新

  • dongyi7901 2014-02-25 01:49
    关注

    Usually, you would do steps like this to use the stored procedure. Check the users on both places, the PHP files and the SQL procedure on the database.

    I usually have a separate process for the connection, but this is more or less a representation of the sequence

    <?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 );
    ?>
    

    You also have to check the procedure itself, because it may have a DEFINER set, like this:

    CREATE DEFINER = 'user'@'localhost' PROCEDURE `your_procedure`
    ...
    SQL SECURITY DEFINER
    

    The security parameter may be INVOKER.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算