Jump to content

Recommended Posts

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");

Link to comment
https://forums.phpfreaks.com/topic/294495-deprecated-mysql_connect/
Share on other sites

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

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());

?> 

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

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.

  • Like 2
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.