Jump to content

Deprecated: mysql_connect()


bielikMM

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
Share on other sites

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

?> 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.