如果我在没有存储过程调用的情况下运行这个模型程序意味着工作正常。但是如果我调用存储过程意味着抛出错误。请帮助我,我认为调用存储过程时表示表名的方式是错误的。
型号
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Members_model extends CI_Model
{
function select_members()
{
$query = $this->db->get('users'); //Table Name
$query = $this->db->query("CALL get_members()");// calling stored procedure
return $query->result_array();
}
}
?>
注意:抛出错误 发生数据库错误
Error Number: 2014
Commands out of sync; you can't run this command now
UPDATE `users` SET `username` = 'ThottiJaya', `password` = '28bf' WHERE `id` = 127
Filename: C:\xampp\htdocs\system\database\DB_driver.php
Line Number: 330
最佳答案
根据 MySQL:
C.5.2.14. Commands out of sync If you get Commands out of sync; you can't run this command now in your client code, you are > calling client functions in the wrong order.
This can happen, for example, if you are using mysql_use_result() and try to execute a new query before you have called mysql_free_result(). It can also happen if you try to execute two queries that return data without calling mysql_use_result() or mysql_store_result() in between.
我假设,在调用 update
之前,您已经打开了一些结果集但尚未使用。这就是错误所在。如果您与结果无关,那么您应该调用mysql_free_result()
,然后进行update
调用。
引用:MySQL: Commands out of sync
引用类似帖子:
SO: Why I am getting the Error “Commands out of sync; you can't run this command now”
还有一种情况,您需要将 mysql 驱动程序更改为 mysqli
。
引用类似帖子:
SO: MySQL Error - Commands out of sync; you can't run this command now
希望这有帮助。
关于php - 调用存储过程时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20328130/