If after upgrading PHP or while working on a programming project, you have encountered the following error:
Fatal error: Call to undefined function mysql_query()
The best solution is most likely to use mysqli_query() instead.
Simple MySQLI Example:
$mysqli_connection = new mysqli("localhost", "user", "password", "database");
$result = $mysqli_connection->query("SELECT id FROM test ORDER BY id ASC");
$mysqli_connection->close();
Why Doesn’t mysql_query() Work in PHP 7?
PHP has historically offered two different extensions for connecting to and communicating with a MySQL database, (these extensions being called MySQL and MySQLI.)
As of PHP 7.0, mysql_query() has been removed as it has been depreciated since 5.5.0.
Note: If you cannot use MySQLI because you do not have the ability to update the application’s code, you will have to downgrade the version of PHP that your server is using.