问题
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