0

I am calling a procedure in code igniter and when I try to call another procedure I get the following error:

Error Number: 2014

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

call get_post_info($id)

Filename: C:/Apache24/htdocs/application/models/Posts_model.php

Line Number: 18

I think I need to clear the result set... not sure.

Here is my model:

<?php class Posts_model extends CI_Model {

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

    public function get_post_ids($acc_id){

        $query = $this->db->query('call get_post_ids('.$this->db->escape($acc_id).')');
        return $query->row_array();
    }

    public function get_post($id)
    {
        $query = $this->db->query('call get_post_info($id)');
        return $query->row_array();
    }
}

In my controller:

$post_ids = $this->posts_model->get_post_ids(1);
foreach ($post_ids as $id){

    array_push($data, $this->posts_model->get_post($id));
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
js091514
  • 165
  • 1
  • 9

1 Answers1

0

I didn't actually run these solutions, but I found some info that might be what you look for. First of all, check this post about the cause of the problem.

I suppose $query->free_result() should solve the problem:

public function get_post_ids($acc_id){
    $query = $this->db->query('call get_post_ids('.$this->db->escape($acc_id).')');
    $result = $query->row_array();
    $query->free_result();
    return $result;
}

And in case that doesn't work, this this may be a good solution for CodeIgniter.

Community
  • 1
  • 1
Vali S
  • 1,471
  • 2
  • 10
  • 18