-3

I am seeing this error on my website.

Deprecated: mysql_query(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/u857740002/public_html/datafetch.php on line 3

Deprecated: mysql_query(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/u857740002/public_html/datafetch.php on line 23

I am using this code.

Can anyone correct these two lines.

$siteSettings = mysql_query("select * from pu_settings where sid = '1' ");
$siteSoft = mysql_query("select * from pu_softwares where slug = '$slug' ");
Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98
Zeeshan
  • 43
  • 1
  • 13
  • 2
    possible duplicate of [The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead](http://stackoverflow.com/questions/13944956/the-mysql-extension-is-deprecated-and-will-be-removed-in-the-future-use-mysqli) – Stephen Kennedy Jul 03 '15 at 07:28
  • This is a warning you can still use mysql_query but its old and unsafe, use http://php.net/manual/en/mysqli.query.php instead, or the next generation http://php.net/manual/en/class.pdo.php. – Ogelami Jul 03 '15 at 07:28

3 Answers3

3

MySQL_* is deprecated and is going to be removed very soon with PHP. Use MySQLi_*. See: MySQLi

Use this instead:

$link = mysqli_connect([dbhost],[dbusername],[dbpass],[dbname]);

$siteSettings = mysqli_query($link,"select * from pu_settings where sid = '1' ");
$siteSoft = mysqli_query($link,"select * from pu_softwares where slug = '$slug' ");
bnahin
  • 796
  • 1
  • 7
  • 20
2

mysql_* is deprecated+removed library so use mysqli_* or PDO:-

suppose your database connection object is $conn

$siteSettings = mysqli_query($conn,"select * from pu_settings where sid = '1' ")or die(mysqli_error($conn));
$siteSoft = mysql_query($conn,"select * from pu_softwares where slug = '$slug' ")or die(mysqli_error($conn)); 

The code to create a connection using mysqli_* is:-

$conn=mysqli_connect("hostname","username","password","databasename");

if (mysqli_connect_errno()){
 echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98
1

Use mysqli_* instead of mysql_* in your query.

$con=mysqli_connect("localhost","my_user","my_password","my_db");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

$siteSettings = mysqli_query($con,"select * from pu_settings where sid = '1' ");
$siteSoft = mysqli_query($con,"select * from pu_softwares where slug = '$slug' ");
Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98
Cyclotron3x3
  • 2,188
  • 23
  • 40
  • Is it right what you wrote because my knowledge says that mysqli_query need two parameters that is connection object and query. You are giving query only, where is connection object? – Alive to die - Anant Jul 03 '15 at 07:36
  • temporal blindness..:) – Cyclotron3x3 Jul 03 '15 at 07:40
  • You could also use the oop style, which is more convenient if you're firing more queries then only one: `$mysqli = new mysqli($host, $user, $pass, $db); $result = $mysqli->query('SELECT * FROM world WHERE people='awesome')` – giorgio Jul 03 '15 at 07:44