CodeIgniter Forums
MySQL, Querybuilder, Controller problems... ERR 2014 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: General Help (https://forum.codeigniter.com/forum-24.html)
+--- Thread: MySQL, Querybuilder, Controller problems... ERR 2014 (/thread-67643.html)



MySQL, Querybuilder, Controller problems... ERR 2014 - cyrus - 03-19-2017

Hello everyone,

I'm new to CI and haven't been into php for quite a while and now I'm stuck and don't get it to run. Tought it'd be an easy task, so in short:

Using a controller "Suppliers" which has a method "details", which will then call a view containing general details and a list of entries from another table. The view tells me that an error occured: 

Code:
Error Number: 2014

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

So to get the info needed:

My Controller
PHP Code:
class Suppliers extends CI_Controller {

 
       public function __construct()
 
       {
 
           parent::__construct();
 
           $this->load->model('suppliers_model');
 
           
            
            
//Check if logged in already
 
           session_valid();
 
       }

public function 
details($id NULL)
 
       {
 
           $data['supplier'] = $this->suppliers_model->get_supplier($id);
            if (empty($data['supplier'])) show_404();

            $data['certificates'] = $this->suppliers_model->get_supplier_certificates($id);


            $data['title'] = $this->lang->line('supplier'FALSE) . ': ' $data['supplier']['name'];

            $this->load->view('templates/header'$data);
            $this->load->view('suppliers/details'$data);
            $this->load->view('templates/footer');
 
       

My Model
PHP Code:
class Suppliers_model extends CI_Model {

 
       public function __construct()
 
       {
 
           $this->load->database();
 
       }

 
       public function get_suppliers($id FALSE)
 
       {
 
           if ($id === FALSE)
 
           {
 
               //$query = $this->db->get('suppliers');
 
               $query $this->db->query('call read_supplier_list()');
 
               return $query->result_array();
 
           }


 
           $query $this->db->query('call read_supplier(' $id ')');
 
           //$query = $this->db->get_where('suppliers', array('id' => $id));

 
           return $query->row_array();
 
       }

 
       public function get_supplier_certificates($supplier_id)
 
       {
 
           //$query = $this->db->query('call read_supplier_certificates(' . $supplier_id . ')');
 
           $query $this->db->get_where('supplier_certificates', array('supplier_id'$supplier_id));
 
           return $query->result_array();
 
       


So, pleasy tell me where I'm wrong... I dont' get it Sad


RE: MySQL, Querybuilder, Controller problems... ERR 2014 - PaulD - 03-19-2017

I have never seen that error before.

A quick google gave me this: http://wikifixes.com/errors/b/0x/Error%202014/?utm_source=bing&utm_medium=cpc&utm_campaign=Bing.WF.S.all.ErrorN.Cod.MB&utm_term=%2BError%20%2B2014&utm_content=Number_Error%202014

So it seems that you have a system error that CI is running on. Something not installed correctly perhaps? Not much use I agree but I am guessing this is not a CI issue, but your local setup or a host environment problem.

Best wishes,

Paul


RE: MySQL, Querybuilder, Controller problems... ERR 2014 - cyrus - 03-19-2017

Thanks for trying... at least I got around that error by not using stored procedures but CI-Querybuilder. Was not able to use a subquery this way, but it worked with grouping.


RE: MySQL, Querybuilder, Controller problems... ERR 2014 - arma7x - 03-19-2017

http://stackoverflow.com/questions/8891179/mysql-error-2014-commands-out-of-sync-you-cant-run-this-command-now


RE: MySQL, Querybuilder, Controller problems... ERR 2014 - InsiteFX - 03-19-2017

Try this and see if the error goes away.

PHP Code:
class Suppliers_model extends CI_Model {

    public function 
__construct()
    {
        
$this->load->database();
    }

    public function 
get_suppliers($id FALSE)
    {
        
$data = array();

        if (
$id === FALSE)
        {
            
//$query = $this->db->get('suppliers');
            
$query $this->db->query('call read_supplier_list()');
            
$data  $query->result_array();

            
$query->free_result();
            return 
$data;
        }

        
$query $this->db->query('call read_supplier(' $id ')');
        
//$query = $this->db->get_where('suppliers', array('id' => $id));

        
$data $query->row_array();
                
        
$query->free_result();
        return 
$data;
    }

    public function 
get_supplier_certificates($supplier_id)
    {
        
$data = array();
            
        
//$query = $this->db->query('call read_supplier_certificates(' . $supplier_id . ')');
        
$query $this->db->get_where('supplier_certificates', array('supplier_id'$supplier_id));
        
$data  $query->result_array();
                
        
$query->free_result();
        return 
$data;
    }