How do I change from mysql to mysqli ?
I have a script that is written in PHP and MySql. It works well.
However, I think it is now time to convert to MySqli.
I am using: php-5.3.3-14.el6_3.x86_64 and mysql-5.1.66-2.el6_3.x86_64 on CentOS release 6.3 (Final)
I have a global.php file which is called in my add.php page
My global.php contains:
I have a few scripts, that were written over the years, that could do with converting.
This is pretty good so far for easy conversions with procedural mysqli.
Connection is easier:
As for querying and errors, without going into prepared statements, you can almost use what you have. The mysql_query is replaced with mysqli_query, and the parameters are reversed. So the $link is ALWAYS required and is the first argument.
The error calls are the same, just again with mysqli_error/errno instead of the mysql_error/errno.
So your previous use of $link as a requirement, will actually help you with the conversion process.
Hi Fou-Lu ...
Many thanks for your advise.
I didn't realise how easy it was.
I have tried in the past, but I think that I didn't put $link first, so it didn't work.
I made the same mistake this time, but went back to your post a read it more closely.
I have now changed my current project to mysqli.
I will now change all my other database projects.
|All times are GMT +1. The time now is 08:52 AM.|
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.