php - 在php + mysql中调用超过1个存储过程

标签 php mysql stored-procedures

DELIMITER $$

USE `test`$$

DROP PROCEDURE IF EXISTS `sp_update_NotifyTrainerStatus_in_notification_table`$$

CREATE DEFINER=`root`@`%` PROCEDURE `sp_update_NotifyTrainerStatus_in_notification_table`(IN email VARCHAR(50), IN id BIGINT)
BEGIN

 SELECT @employee_id := `Employee_Id` FROM `employee_profile` WHERE `Email_Id` = email;

 UPDATE notification_status_table SET NotifyTrainerStatus=1 WHERE Employee_Id    =@employee_id AND Training_Id = id;

END$$

DELIMITER ;

这是我的 mysql 查询,我必须在 id=6 时运行它。我的 PHP 代码如下所示

if ( $id == 6 ) {
    // echo $trainingid;
    // echo "Inside id=6";
    mysql_query("call update_notify_trainer_in_status_table(" . $trainingid  . ")");
    $n = count( $to );
    // echo "count : ".$n;
    // foreach( $to as $values ) {
    for( $i = 0; $i < $n; $i++ ) {
        // echo $values;
        $trainer_mail = $to[$i];
        echo $trainer_mail;
        //echo $trainingid;
        mysql_query("call  sp_update_NotifyTrainerStatus_in_notification_table('".$trainer_mail."' , " . $trainingid . ")")  or die( mysql_error() );
    }
}

我的问题是此查询对第一个 $trainer_mail 运行良好,但对第二个 $trainer_mail 运行不正常。有什么建议。 提前致谢。

最佳答案

您需要在每次调用存储过程后清理连接。 试试这个:

function mysqli_clean_connection($dbc) {
    while(mysqli_more_results($dbc)) {
        if (mysqli_next_result($dbc)) {
            $result = mysqli_use_result($dbc);
            if ($result!=NULL) {
                mysqli_free_result($result);
            }
        }
    }
}

我用的是mysqli,不过你可以适配

关于php - 在php + mysql中调用超过1个存储过程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14869530/

相关文章:

php - 在 PHP 中从数字序列创建字符序列

php - 将绝对/固定 div 包装在相对 div 中

php - 使用 php print 删除部分 url

mysql - 如何显示不存在值的行

stored-procedures - 如何遍历引用虚拟图的 SPARQL 查询?

c# - MySql 存储过程参数转义

php - jQuery 解析/显示来自 php json_encode 的 json 数据

MySQL - 组合 max 和 concat 函数

mysql 连接器问题

PostgreSQL 函数选择*