Tutorial: Solve mysql extension is deprecated & will be removed in the future of PHP (PHP)
After a long discussion inside the PHP developers team they decided to mark the old mysql_* functions deprecated in PHP 5.5. In this short tutorial you will get a instruction how to solve this error message.
Why was mysql deprecated in PHP 5.5?
Johannes Schlüter, one of the PHP developers listed missing points like these:
- Stored Procedures
- Prepared Statements
- Full charset support
How to solve the warnings?
Currently mostly many MySQL connections in PHP use this construct:
$link = mysql_connect('localhost', 'user', 'password');
The way with MySQLi would be like this:
$link = mysqli_connect('localhost', 'user', 'password', 'dbname');
To run database queries is also simple and nearly identical with the old way:
mysql_query('CREATE TEMPORARY TABLE `table`', $link);
mysqli_query($link, 'CREATE TEMPORARY TABLE `table`');
Besides the shown possibility there's are also solutions like using MySQLi in object oriented style or even switch to PHPs PDO (PHP Data Objects) like shown in this PDO Tutorial for MySQL Developers.
Filthy and fastest solution
Suppress all deprecated warnings including them from mysql_*:
error_reporting(E_ALL ^ E_DEPRECATED);
If you have further questions: Just left them below in the comments.
Happy coding :)
Source: PHP Internal Wiki