bielikMM Posted February 10, 2015 Share Posted February 10, 2015 Hi Am getting this error in my php code Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in C:\wamp\www\matu\connect.php on line 9 the line is $con=mysql_connect("$host", "$username", "$password")or die("cannot connect"); Quote Link to comment https://forums.phpfreaks.com/topic/294495-deprecated-mysql_connect/ Share on other sites More sharing options...
PravinS Posted February 10, 2015 Share Posted February 10, 2015 mysql_connect() function is not supported in PHP 5.5.0 and your PHP version may have been upgraded to 5.5.0 check this url: http://php.net/manual/en/function.mysql-connect.php Quote Link to comment https://forums.phpfreaks.com/topic/294495-deprecated-mysql_connect/#findComment-1505324 Share on other sites More sharing options...
gristoi Posted February 10, 2015 Share Posted February 10, 2015 ok, it is telling you what you need to know. mysql is no longer used in later php versions, you need to start using PDO Quote Link to comment https://forums.phpfreaks.com/topic/294495-deprecated-mysql_connect/#findComment-1505325 Share on other sites More sharing options...
cyberRobot Posted February 10, 2015 Share Posted February 10, 2015 ok, it is telling you what you need to know. mysql is no longer used in later php versions, you need to start using PDO While PDO is probably a better choice...you could also use MySQLi. More information about the two options can be found here: http://php.net/manual/en/mysqlinfo.api.choosing.php Quote Link to comment https://forums.phpfreaks.com/topic/294495-deprecated-mysql_connect/#findComment-1505333 Share on other sites More sharing options...
bielikMM Posted February 12, 2015 Author Share Posted February 12, 2015 Tthanks guys am getting to figure out using PDO and MYSQLI.....perhaps you could help me with this string of code. how will the new string look like ? <?php $host="127.0.0.1"; // Host name $username="root"; // mysql username $password=""; // mysql password $db_name="marketapp"; // Database name // Connect to server and select databse. $con=mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("marketapp",$con ) or die(mysql_error()); ?> Quote Link to comment https://forums.phpfreaks.com/topic/294495-deprecated-mysql_connect/#findComment-1505519 Share on other sites More sharing options...
cyberRobot Posted February 12, 2015 Share Posted February 12, 2015 how will the new string look like ? The link I provided earlier (http://php.net/manual/en/mysqlinfo.api.choosing.php) shows how to connect to a database with PDO, MySQLi, and MySQL. Quote Link to comment https://forums.phpfreaks.com/topic/294495-deprecated-mysql_connect/#findComment-1505526 Share on other sites More sharing options...
bielikMM Posted February 12, 2015 Author Share Posted February 12, 2015 Alright thanks for the help @Guru Quote Link to comment https://forums.phpfreaks.com/topic/294495-deprecated-mysql_connect/#findComment-1505529 Share on other sites More sharing options...
Tom10 Posted February 12, 2015 Share Posted February 12, 2015 Hi Am getting this error in my php code Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in C:\wamp\www\matu\connect.php on line 9 the line is $con=mysql_connect("$host", "$username", "$password")or die("cannot connect"); Yes like cyberRobot said, mysql functions are now deprecated (out of date) they may be removed from PHP in the future, you are using mysql_connect() Here's a mysqli example: $host = "localhost"; $username = "dbUser"; $password = "NULL"; $db_name = "dbName"; $conn = mysqli_connect($host, $username, $password, $db); if($conn->connect_error()) { //If there is an error while connecting to SQL server //Execute code ie: echo $conn->connect_errono(); //Display Error Number } else { //Do Nothing } Or like cyberRobot also said you can use PDO Quote Link to comment https://forums.phpfreaks.com/topic/294495-deprecated-mysql_connect/#findComment-1505552 Share on other sites More sharing options...
brotherZ Posted February 12, 2015 Share Posted February 12, 2015 Looks like a warning. You should fine if you disable php warnings. Quote Link to comment https://forums.phpfreaks.com/topic/294495-deprecated-mysql_connect/#findComment-1505557 Share on other sites More sharing options...
CroNiX Posted February 12, 2015 Share Posted February 12, 2015 Looks like a warning. You should fine if you disable php warnings. Why would you want to turn off a deprecation notice? Its kind of important to not use things that are going to be removed from PHP if you want things to work in the future. 2 Quote Link to comment https://forums.phpfreaks.com/topic/294495-deprecated-mysql_connect/#findComment-1505560 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.