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

Thread Solved

Join Date: May 2007
Posts: 459
Reputation: Atli is on a distinguished road 
Solved Threads: 57
Atli's Avatar
Atli Atli is offline Offline
Posting Pro in Training
 
0
  #11
Nov 2nd, 2009
I'm glad you got it working

Originally Posted by sam023 View Post
but in coding i made two config file.. one with mysql other with msqli..!!!
That's actually pretty bad. Really bad, to be honest :/
You've got two open connections now, which is just a waste.

I strongly recommend you try to use the function I posted in my first post, or at least use the mysqli functions to do both queries, like:
  1. // Call the first procedure
  2. $result1 = mysqli_query($dbLink, "CALL `TestProc`(1);");
  3.  
  4. // Do something with the result
  5. // etc...
  6.  
  7. // Free the results up for the next query
  8. mysqli_free_result($result1);
  9. while(mysqli_more_results($dbLink) && mysqli_next_result($dbLink)) {
  10. $dummyResult = mysqli_use_result($dbLink);
  11. if($dummyResult instanceof mysqli_result) {
  12. mysqli_free_result($dbLink);
  13. }
  14. }
  15.  
  16. // Call the next procedure
  17. $result2 = mysqli_query($dbLink, "CALL `TestProc`(2);");
  18. // etc...
This way you can drop the old mysql connection but still do both procedures.

Originally Posted by sam023 View Post
can u give link to basic tutorial of mysqli..?
There is hardly any need for a tutorial like that. The mysqli extension was designed to replace the old mysql extension very easily, and almost everything else you need to know can be found in the manual. Every function is documented there, with loads of examples and user submitted comments.

But to replace the old mysql functions, there are only two things you really need to know:

#1 The way you connect to a database is different:
  1. $mysqli = new mysqli("localhost", "my_user", "my_password", "db_name");
  2.  
  3. /* check connection */
  4. if (mysqli_connect_errno()) {
  5. printf("Connect failed: %s\n", mysqli_connect_error());
  6. exit();
  7. }

#2 You need to pass the database object (the $mysqli in the previous example) into the query function as the first parameter:
  1. mysqli_query($mysqli, "SELECT something");

Knowing those two things, you should be able to code almost exactly as you would have using the old mysql extension. The function names are almost identical, except for the added "i" ;-)

There are of course a few new features that you can use, now that you have upgraded.
Like:
  • OOP. The mysqli object is in fact an object, which allows for OOP style syntax. Just pick any mysqli function in the manual and check out the OOP examples and see the difference.
  • Prepared statements (See the examples). Eliminates the risk of SQL Injection, which is one of the biggest security risks for PHP applications.
  • Improved speed! Nuff said.
  • Execute multiple queries at once, via the mysqli::multi_query method.
  • Transactions. Gives you the ability to execute a series of queries, but only committing the changes to the database when you are ready, or rollback the changes in case of a problem.
There is probably more that I'm not remembering right now :-]
Last edited by Atli; Nov 2nd, 2009 at 5:04 am.
Please do not ask for help in a PM. Use the forums.
And use [code] tags!
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 121
Reputation: sam023 is an unknown quantity at this point 
Solved Threads: 2
sam023 sam023 is offline Offline
Junior Poster
 
0
  #12
Nov 2nd, 2009
thanks a load for such a useful info.!!

u rock..
Last edited by sam023; Nov 2nd, 2009 at 8:25 am.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the PHP Forum


Views: 521 | Replies: 11
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC