Getting error? The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead [duplicate].

Published on : April 27, 2026

Author:

Category: PHP


This warning basically appears for upgrading you server to PHP 5.5.

Solution 1:
If you don’t want to change your code just add into header below code –

[sourcecode]error_reporting(0);[/sourcecode]

Solution 2:
Update your database connection as like below-

[sourcecode]
try {
$db = new PDO(‘mysql:host=localhost;dbname=your_db_name’, ‘db_user_name’, ‘db_password’);
}
catch (Exception $e) {
echo ‘Error!’;
}
finally {
echo ‘Unexpected exception occurs’;
}
[/sourcecode]