php - 调用存储过程时出错

标签 php mysql codeigniter stored-procedures

如果我在没有存储过程调用的情况下运行这个模型程序意味着工作正常。但是如果我调用存储过程意味着抛出错误。请帮助我,我认为调用存储过程时表示表名的方式是错误的。

型号

 <?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/

相关文章:

php - 将图像上传到 mysqli 数据库时出现问题

php - 简单的PHP随机数组

php - 成功更改 apache 服务器的端口后,我的项目没有打开。我可以使用新端口号访问管理面板

Mysql查询显示从a到p范围内的名称

php - 在PHP中将当前日期添加到mysql数据库

php - XML 到数组? [PHP]

php - 向特定用户发送推送通知

mysql - Angular - 在 Zeppelin 中将动态表单内容插入数据库

php - Tank Auth 登录在本地成功,在服务器上失败

php - 如何使用codeigniter将已删除的记录存储在mysql数据库中