E
E
Evgeny Ivanov2021-06-30 11:55:01
PHP
Evgeny Ivanov, 2021-06-30 11:55:01

How to replace mysql with mysqli in a project?

Once upon a time, I wrote a project in php (website, system) and used a connection to the database via mysql.
Of course, this extension is outdated. And it does not work with the current configuration.
Changing the configuration (even Open Server) does not make sense, just like installing outdated LAMP (if it is still possible).

Having tried to change mysql to mysqli, I ran into a problem - a bunch of functions throughout the project are configured to work with mysql:
mysql_fetch_assoc
mysql_query
mysql_num_rows
....

Even mass replacements through notepad++ (replace text in files) did not help much.
After all, mysqli needs a connection reference. It is necessary to transfer it, change the code of functions - their calls, parameters ..
This is rewriting 30% of the project, debugging ...

What to do?
How to replace mysql with mysqli in a project?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
SagePtr, 2021-06-30
@logpol32

There are layer libraries that emulate the old mysql extension using PDO or MySQLi. You just need to include them somewhere before the code that connects to the database. Here are a few of them offhand:
https://github.com/dshafik/php7-mysql-shim
https://github.com/dotpointer/mysql-shim

R
Rsa97, 2021-06-30
@Rsa97

Option 1 is to write a library that mimics the behavior of mysql_ functions.
Option 2 - partially rewrite the code, replacing mysql_ calls with mysqli_ with the appropriate refinement.
Option 3 - completely rewrite the project for a modern version of PHP.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question