Welcome Guest, Not a member yet? Register   Sign In
Command out of sync
#4

[eluser]Tim Brownlaw[/eluser]
I simply added the following into mysqli_result.php that is missing this command for some strange reason.
(under /system/database/drivers/mysqli/mysqli_result.php)

Code:
// --------------------------------------------------------------------
  /**
   * Read the next result
   *
   * @return  null
   */  
  function next_result()
  {
    if (is_object($this->conn_id))
    {
      return mysqli_next_result($this->conn_id);
    }
  }
  // --------------------------------------------------------------------

Then in my model, I simply call $result->next_result() to loose the expected extraneous resultset;

As an example, I have a stored procedure for adding a new member which I call in a model as the following function call.
Code:
// Calling  Stored procedure add_reg_member
// Returns an array in the form...
//      $row['result'] ( 0 = success )
//      $row['message'] (if there is an error - why)
//      $row['last_id'] - last insert id (could test this instead of result, but let's stay consistent)
  function add_reg_member($db_data)
  {
// using the active record structure to test it
    $sql = 'CALL member_register(?,?,?,?,?,?,?,?,?)';
    $params =array(
      $db_data['username'],
      $db_data['firstname'],
      $db_data['lastname'],
      $db_data['email'],
      $db_data['password'],
      $db_data['country'],
      $db_data['validation_code'],
      $db_data['date_reg'],
      $db_data['valid'] );
   $result = $this->db->query($sql,$params);

  if(($result) && ($result->num_rows() > 0))
  {
     $row = $result->row_array();
  }
  else
    $row =array('result'=>1,'message'=>'Something went horribly wrong with the DB','last_id'=>0); // Database Problem - die gracefully.

  $result->next_result(); // Dump the extra resultset.
  $result->free_result(); // Does what it says.
  return $row; // Return the row to the controller that called it.
  }

My stored procedure, while performing an insert, returns a few values I want to test and use.
For instance, when a duplicate username is encountered and the last inserted id.

So adding in the actual mysqli_next_result into mysqli_result.php fixed up all my problems. Well my CI ones Smile

Plus I can still use the active record stuff...
I'm not sure why this isn't in CI already. I checked version 1.7.1 and it's not there.

Hope that helps someone!

Now, what was I doing a few hours ago before I got stuck on this?


Messages In This Thread
Command out of sync - by El Forum - 03-09-2008, 09:40 AM
Command out of sync - by El Forum - 04-02-2008, 01:57 PM
Command out of sync - by El Forum - 06-16-2008, 10:39 AM
Command out of sync - by El Forum - 04-13-2009, 01:07 AM
Command out of sync - by El Forum - 06-27-2009, 07:52 PM
Command out of sync - by El Forum - 08-08-2011, 06:30 AM
Command out of sync - by El Forum - 08-08-2011, 09:40 PM
Command out of sync - by El Forum - 08-09-2011, 02:58 AM
Command out of sync - by El Forum - 06-05-2014, 04:04 AM
Command out of sync - by El Forum - 06-05-2014, 12:07 PM
Command out of sync - by El Forum - 06-05-2014, 03:03 PM



Theme © iAndrew 2016 - Forum software by © MyBB