In the light of MySQL to soon be deprecated, I need to move a large website using ADODB from MySQL to MySQLi.
Now I have looked up a few topics on Stackoverflow and thanks to the community I already have a genral idea of what needs to be done. Best topics on the matter are those ones:
Switch large website from MySQL to MySQLi
However, I do still need a bit more clarification on my particular case, where ADODB is being used.
This is what I use to connect to the DB:
define('DBHOST', 'db_host');
define('DBUSER', 'db_user');
define('DBPASS', 'db_pass');
define('DBNAME', 'db_name');
include('adodb/adodb.inc.php');
$db = ADONewConnection('mysql');
$db->Connect(DBHOST,DBUSER,DBPASS,DBNAME) or die("Database not found!");
So first I am changing:
$db = ADONewConnection('mysql');
to
$db = ADONewConnection('mysqli');
That's the easy part, I guess.
Now since I am using ADODB, do I also need to change all instances of MySQL_* functions to MySQLi_* or ADODB takes care of this automatically? I think I know the answer but anyhow have to ask.
My most common MySQL_ functions are:
mysql_insert_id()
mysql_query()
mysql_fetch_array()
mysql_num_rows()
mysql_escape_string()
mysql_connect()
mysql_select_db()
mysql_error()
Most common usage is like $variable = mysql_insert_id();
or $v1 = mysql_query($v);
Is there anything else I should take into consideration when moving from MySQL to MySQLi for ADODB?
"do I also need to change all instances of MySQL_* functions to MySQLi_* ?"
The answer is yes. Different MySQL APIs/functions do not intermix. You must use the same API/functions from connection to querying.
You can use the following functions, simply replacing mysql_
by mysqli_
, while passing a database connection in functions that require it and as the first parameter.
mysqli_query($connection, $query)
. They are marked with asterisks *
.
mysqli_insert_id() - *
mysqli_query() - *
mysqli_fetch_array()
mysqli_num_rows()
mysqli_escape_string() - *
mysqli_connect() - *
mysqli_select_db() - *
mysqli_error() - *
1) I would suggest you to use pdo_mysql instead of mysql since it has better support for transactions.
2) ADODB initializes the driver being used (eg mysql or pdo_mysql) by using the dsn identifier from the connection string ie pdo_mysql://localhost/mydb or mysql://localhost/mydb.
Just switch mysql -> pdo_mysql in the connection string and it starts to use mysqli -driver instead.
3) Driver loading logic is located on row ~4860 at adodb.inc.php, and at least in the version I'm using from composer, there is no switch to be able to configure mysqli, but it upgrades mysql -> mysqli automatically if you have PHP 7.0.0 or higher. You could tweak this code to force mysqli also by adding one if-statement, but then you have a custom fork of ADODB. Maybe do a pull request.
case 'mysql':
// mysql driver deprecated since 5.5, removed in 7.0
// automatically switch to mysqli
if(version_compare(PHP_VERSION, '7.0.0', '>=')) {
$db = 'mysqli';
}
$class = $db;
break;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.