![]() |
Command out of sync - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Command out of sync (/showthread.php?tid=6716) Pages:
1
2
|
Command out of sync - El Forum - 03-09-2008 [eluser]stathis[/eluser] It seems that when you try to call at 2 stored procedures at the same routine, you get an error like this: "Command out of sync" This error is caused due to the fact that mySQL Stored Procedures return MULTI RESULTS even if there is only one select statement in them. In PHP, you over come this by using mysqli_multi_query. In CI, i re-writed funcion _execute, located in system/database/drivers/mysqli/mysqli_driver.php using the following code: Code: function _execute($sql) Please note that the above, leaves out the possibility for one to actually need to have multiple results in one procedure call. Command out of sync - El Forum - 04-02-2008 [eluser]Unknown[/eluser] When I tried to modify mysqli_driver.php as you showed none of my other regular SQL queries would work. So this is what I did... Code: function _execute($sql) I guess if you stuck to always using 1 case of the call command you could avoid the hit of the case insensitive string functions. I really wish I could find a more elegant solution to this and still use syntax like $this->db->query("call someStoredProcedure"); Command out of sync - El Forum - 06-16-2008 [eluser]Yauhen_S[/eluser] Hi! I was solve this problem in other way. Below is a _execute method code: Code: // Free result from previous query About check for error in last lines. This is because mysqli_store_result can return false not only if error occur, but also if query don't return resultset. Unfortunately CI checks only returned value for false and in this case "Error Number: 0" occures. PS: I'm not sure that this will works with regular query, i'm using only stored routines in my current project. Command out of sync - El Forum - 04-13-2009 [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: // -------------------------------------------------------------------- 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 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 ![]() 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? Command out of sync - El Forum - 06-27-2009 [eluser][email protected][/eluser] Thanks man! You helped me! I really like CI but mulple resultsets support is missing! OMFG! Command out of sync - El Forum - 08-08-2011 [eluser]Rahul gamit[/eluser] thank you so much this works for me , thanks a lot Command out of sync - El Forum - 08-08-2011 [eluser]CodeIgniteMe[/eluser] This is where MS SQL Server is better Command out of sync - El Forum - 08-09-2011 [eluser]nikes[/eluser] thank you so very much this performs for me , many thanks a great offer Command out of sync - El Forum - 06-05-2014 [eluser]charly87[/eluser] Hi. Thanks for the solution. It started working fine for me but now i'm getting this error: <p>Severity: Warning</p> <p>Message: Illegal string offset 'username'</p> <p>Filename: my_model.php</p> <p>Line Number: 96</p> What is the problem? This is my model function: PHP Warning, illegal offset 'username' I'm doing an ajax request and the error is in $params =array( $db_data['username'] ); // 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 validate_UserExists(?)'; $params =array( $db_data['username'] ); $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. } Hope you can help me. Thanks Command out of sync - El Forum - 06-05-2014 [eluser]CroNiX[/eluser] It looks like your $db_data array that you are passing to your add_reg_member() method does not contain a 'username' index. The problem most likely isn't in the code you posted, but wherever you are calling that method from. |