CodeIgniter 3: Error Number 2014 Commands out of sync; you can't run this command now

拟墨画扇 提交于 2019-12-11 08:46:13

问题


I am receiving MySQL error number 2014 every time I call the 2nd stored procedure (insert_staff_logs) in CodeIgniter 3.

Here is the complete error generated:

A Database Error Occurred

Error Number: 2014

Commands out of sync; you can't run this command now

CALL insert_staff_logs('1000',now(),'LOGIN')

Filename: C:/wamp/www/db2/system/database/DB_driver.php

Line Number: 691

Here is my Model:

class Login_model extends CI_Model
{
public function login($data)
{
    $query = $this->db->query("CALL login_auth('".$data['username']."','".$data['password']."')");
    if($query->num_rows() == 1)
    {
        return $query->result();
    }else
    {
        return false;
    }
}

public function staff_logs($data)
{
    $query = $this->db->query("CALL insert_staff_logs('".$data."',now(),'LOGIN')");
}
}

And here is my stored procedure:

DELIMITER $$

CREATE
/*[DEFINER = { user | CURRENT_USER }]*/
PROCEDURE `must_empc_db`.`insert_staff_logs`(id VARCHAR(10),s VARCHAR(50))

BEGIN
INSERT INTO tblstafflogs(`staffID`,`timestamp`,`session`)
VALUES(id,NOW(),s);
END$$

DELIMITER ;

Does anyone has solution on this? Your reply is much appreciated. Thanks!


回答1:


class Login_model extends CI_Model
{
    public function login($data)
    {        
        if (mysqli_more_results($this->db->conn_id)) {
            mysqli_next_result($this->db->conn_id);
        }
        $query = $this->db>query("CALLlogin_auth('".$data['username']."','".$data['password']."')");
        if($query->num_rows() == 1)
        {
            return $query->result();
        }
        else
        {
            return false;
        }
    }

    public function staff_logs($data)
    {
        if (mysqli_more_results($this->db->conn_id)) {
            mysqli_next_result($this->db->conn_id);
        }
        $query = $this->db->query("CALL insert_staff_logs('".$data."',now(),'LOGIN')");
    }
}


来源:https://stackoverflow.com/questions/42324233/codeigniter-3-error-number-2014-commands-out-of-sync-you-cant-run-this-comman

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!