After upgrading to PHP 7.x from PHP 5.x, you start getting error of “Call to undefined”.
This is because mysql_* functions are completely removed from PHP 7, it was get deprecated in PHP 5.5 but now it is completely removed.
The older mysql function are removed due to following reasons:
- Not work on Object Oriented concept
- Not support transactions and prepared statements
- Insecure
Here is how you can connect to MySQL with MySqli connection object:
<?php $conn = mysqli_connect("localhost", "username", "password", "database"); ?>
or more detailed:
<?php try { $conn = mysqli_connect("localhost", "username", "password") or die("Error: " . $mysqli_connect_error()); $db = mysqli_select_db($conn, "database"); } catch (Exception $e) { die("Unexpected Error: " . $e->getMessage()); } ?>
So, before you upgrade to PHP 7.x, first you must update your code.