Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CodeIgniter switching driver from mysql --> mysqli

I was reading this question: The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead

And it got me thinking that I should make the change from mysql to mysqli. It is a one character change in CodeIgniter so it isn't very hard :)

But is there anything I should look out for to spot any errors that can happen? Are there certain queries that are treated differently?

like image 942
Chris Muench Avatar asked Feb 04 '14 00:02

Chris Muench


People also ask

How do I switch from MySQL to MySQLi?

If you want to convert your script from a MySQL extension to a MySQLi extension manually, you must start with the top of the script and start converting all the methods one by one. For this, open the script in any text editor and use the find-and-replace tool to replace mysql_ with mysqli .

Is MySQLi deprecated?

What does the mysqli extension include? There are three different ways to access a MySQL database. The oldest one uses the MySQL extension, which was deprecated as of PHP 5.5 and fully removed in PHP 7. The mysql() function no longer works in PHP 7.

How can I convert MySQL database to MySQLi in PHP?

To migrate it to MySQLi, we use the mysqli_select_db method to select the database and then the mysqli_query method to run the query and return the result. This statement is replaced with the mysqli_query method using the DROP DATABASE sql... This is a simple name change.

Can you use MySQLi and PDO?

PDO will work on 12 different database systems, whereas MySQLi will only work with MySQL databases. So, if you have to switch your project to use another database, PDO makes the process easy. You only have to change the connection string and a few queries.


1 Answers

Are there certain queries that are treated differently?

No.

The MySQL and MySQLi extension are “drivers” that take care of the communication between PHP and the MySQL database server;

they do not change the range of SQL commands that the MySQL server understands.

So as long as the DB abstraction layer takes care of what PHP functions are to use for what purpose for you (and a framework like CI should most certainly do that), there is nothing to worry about in regard to the actual queries.

like image 134
CBroe Avatar answered Nov 06 '22 20:11

CBroe