| | |
Error: Commands out of sync; you can't run this command now
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
0
#11 Nov 2nd, 2009
I'm glad you got it working 
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:
This way you can drop the old mysql connection but still do both procedures.
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:
#2 You need to pass the database object (the
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:

•
•
•
•
but in coding i made two config file.. one with mysql other with msqli..!!!
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:
php Syntax (Toggle Plain Text)
// Call the first procedure $result1 = mysqli_query($dbLink, "CALL `TestProc`(1);"); // Do something with the result // etc... // Free the results up for the next query mysqli_free_result($result1); while(mysqli_more_results($dbLink) && mysqli_next_result($dbLink)) { $dummyResult = mysqli_use_result($dbLink); if($dummyResult instanceof mysqli_result) { mysqli_free_result($dbLink); } } // Call the next procedure $result2 = mysqli_query($dbLink, "CALL `TestProc`(2);"); // etc...
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:
php Syntax (Toggle Plain Text)
$mysqli = new mysqli("localhost", "my_user", "my_password", "db_name"); /* check connection */ if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); }
#2 You need to pass the database object (the
$mysqli in the previous example) into the query function as the first parameter: php Syntax (Toggle Plain Text)
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.
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!
And use [code] tags!
![]() |
Other Threads in the PHP Forum
- Previous Thread: Run PHP program
- Next Thread: Blowfish Hashing?!?
Views: 520 | Replies: 11
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code cron curl customizableitems database date development directory display download dynamic echo email error file files folder form forms forum function functions google headmethod href htaccess html image include insert integration ip java javascript joomla jquery limit link login loop mail malfunctioning menu methods mlm mod_rewrite multiple mysql oop parse paypal pdf php problem query radio random recursion regex remote script search select server sessions sms soap source space speed sql structure syntax system table tutorial update updates upload url validation validator variable video web xml youtube





