After the wordpress website upgrades the php version, the problem of error reporting in mysql related functions is solved¶
Original link: https://www.itylq.com/wordpress-mysql-errors.html
Release date: 2022-09-17 Migration time: 2026-03-21
Recently, the registration of the new domain name https://www.itylq.com has been approved, and I want to migrate the content from the original website https://leicong.net. Articles, pages, and plug-ins are all running smoothly, but various errors appear when copying the code in the footer that counts visitor IP addresses and the number of visitors.
The operating environment of the original website is PHP5.6, and the new website has been upgraded to PHP7+. I found that mysql functions have changed a lot since PHP7 version. The main ones are as follows:
1. The function name has changed:
The functions related to mysql database operations such as mysql_connect(), mysql_query(), mysql_select_db(), mysql_errno(), mysql_fetch_row() and mysql_close() corresponding to the php5 version have been replaced by the php7 version. Deprecated, an "i" is added after the "mysql" string, and it becomes mysqli_connect(), mysqli_query(), mysqli_select_db(), mysqli_errno(), mysqli_fetch_row(), mysqli_close(), etc.;
**2. The position of the variable parameters in the function has changed: **
For example, in the PHP5 version of mysql_query(), the function parameter is mysql_query(“SET NAMES ‘utf8′”,$conn), with the variables at the end; while in the PHP7 version, the variable parameters of the mysql function are placed first, such as mysqli_query($conn,”SET NAMES ‘utf8′”).
Remarks: In the PHP7 version, in addition to the name "mysql" plus "i" to become "mysqli_XX", the variable parameters must be placed in the first parameter position, otherwise warning messages will appear and the function execution results will not achieve the expected results:

The following is the specific error information reported when copying the PHP5 version of mysql function to the PHP7 environment in actual applications:
**1. Mysql_query() function error: **
PHP Fatal error: Uncaught Error: Call to undefined function mysql_connect() in ./itylq.com/wp-content/themes/puock/footer.php:621
Repair: mysql_query(“SET NAMES ‘utf8′”,$conn) is changed to mysqli_query($conn,”SET NAMES ‘utf8′”)
**2. Mysql_connect() function error: **
Repair: mysql_connect() can be changed to mysqli_connect(), and the function parameters remain unchanged.
3. The mysql_select_db(), mysql_errno(), and mysql_fetch_row() functions report similar error messages: Just modify the function name and place the variable parameters in the first parameter position.
**4. mysql_close() function alarm: **
Fix: This function is a little different than the other functions above. In the PHP5 version, the mysql_close() function does not require parameters; in the PHP7 version, the database connection variable needs to be placed in the function, such as mysqli_close($conn).
Okay, the above is the solution to the problem that mysql related functions report errors due to inconsistent PHP versions during the upgrade or migration process of WordPress and other websites.
This article was moved from WordPress to MkDocs