• Register
0 votes
47 views

Problem :

When I try to connect to the MySQL server from PHP, I see a below error:

“Deprecated: The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /path/to/filename.php on line 123”

The code on a referenced line is as below:

mysql_connect($server, $username, $password);

I am certain that my arguments are correct, and also exact code has been working for many years without a problem. So how can I fix my code?

7 5 2
3,870 points

Please log in or register to answer this question.

1 Answer

0 votes

Solution :

As per your error message suggests, there are the two other MySQL extensions that you can consider: MySQLi and PDO_MySQL, either of which can be used by you instead of ext/mysql. Both have been in the PHP core since v5.0, so if you are using the version that is throwing above deprecation errors then you can very certainly just start using them right away means without any of the installation effort.

They differ slightly, but offer the number of advantages over your old extension including API support for the transactions, stored procedures and your prepared statements (thereby providing a best way to defeat the SQL injection attacks). It helped me and many other PHP developers like me.

9 7 4
38,600 points

Related questions

1 vote
1 answer 6 views
6 views
Problem: I am getting this warning in php but still my program runs correctly. The mysql extension is deprecated and will be removed in the future: use mysqli or pdo instead.
asked Apr 22 PkGuy 23.5k points
1 vote
1 answer 6 views
6 views
Problem: I am unable to delete this error message please help. The mysql extension is deprecated and will be removed in the future: use mysqli or pdo.
asked Mar 29 PkGuy 23.5k points
0 votes
1 answer 13 views
13 views
Problem: the mysql extension is deprecated and will be removed in the future: use mysqli or pdo instead
asked Feb 23 Muneeb Saadii 130k points
0 votes
1 answer 11 views
11 views
Problem: I'll make a submission for a response to my question. Please, I have searched the internet but have not found any useful material, and I am now having trouble continuing my studies.
asked Apr 1 rakib1 51.5k points
0 votes
2 answers 3 views
3 views
Problem: Please assist me in resolving this issue of Deprecated mysql_connect() the mysql extension is deprecated and will be removed in the future.
asked Apr 1 rakib1 51.5k points
0 votes
1 answer 8 views
8 views
Problem: Use of getPreventDefault() is deprecated. Use default prevented instead. Why I'm getting this error and what's the solution for it?
asked Mar 15 ummesalma 29.2k points
0 votes
1 answer 19 views
19 views
Problem: I'm developing an application in CodeIgniter, and I'm getting an error in sending mail while registering. PHP Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; emailcomm has a deprecated constructor in /var/www/html ... now my code doesn't work anymore. I'm going through the error logs showing the above error. How can I fix my code?
asked Apr 24 Yeamin 21.4k points
0 votes
1 answer 6 views
6 views
Problem: Can someone helpme I have to convert an ereg_replace to preg_replace
asked Apr 19 ummesalma 29.2k points
0 votes
1 answer 5 views
5 views
Problem: This code gives a deprecation warning after upgrading to PHP 5.5: $result = preg_replace( "/\{([<>])([a-zA-Z0-9_]*)(\?{0,1})([a-zA-Z0-9_]*)\}(.*)\{\\1\/\\2\}/iseU", "CallFunction('\\1','\\2','\\3','\\4','\\5')", $result ); How can I replace the code with preg_replace_callback()?
asked Apr 23 Jack20 5.1k points
0 votes
1 answer 5 views
5 views
Problem: Do you have any ideas about how I would be able to fix this problem,"the pdo extension is required for this adapter but the extension is not loaded."
asked Apr 9 Humaira ahmed 50.7k points