I am trying to do a simple connection with XAMPP and MySQL server, but whenever I try to enter data or connect to the database, I get this error.
Fatal error: Uncaught Error: Call to undefined function mysql_connect() in C:\xampp\htdocs\register.php:22
Stack trace: #0 {main} thrown in C:\xampp\htdocs\register.php on line 22
Example of line 22:
$link = mysql_connect($mysql_hostname , $mysql_username);
mysql_
functions have been removed from PHP 7. You can now use MySQLi or PDO.MySQLi example:
mysqli_connect
reference linkAs other answers suggest... Some guy(for whatever reason) decided that your old code should not work when you upgrade your php because he knows better than you and don't care about what your code does or how simple it is for you to upgrade.
Well if can't upgrade your project overnight you can
or...
That will keep your old php code a up and running until you are in a mood to update...
Make sure you have not committed a typo as in my case
mysql_*
functions have been removed in PHP 7.You probably have PHP 7 in XAMPP. You now have two alternatives: MySQLi and PDO.
Additionally, here is a nice wiki page about PDO.
You got that error because the
mysql_connect
function (actually, allmysql_*
functions) were removed from PHP 7. You can now use MySQLi or PDO.Example:
mysql_*
functions have been removed in PHP 7.You now have two alternatives: MySQLi and PDO.
The following is a before (-) and after (+) comparison of some common changes to MySQLi, taken straight out of working code: