-5

I am new to PHP and I'm trying to connect to my database with the help of some youtube videos but I get this error

Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in C:\wamp\www\db.php on line 7

Dharman
  • 30,962
  • 25
  • 85
  • 135
user2308205
  • 39
  • 1
  • 2
  • 9

2 Answers2

5

The problem stems from Wampserver's demo SQL files which include mysql_* based functions code.

Sidenote: They really should make a note of that or update their demo files to include test files containing mysqli_ and/or PDO code to leave out the confusion, since the version of PHP that comes with it is 5.5.12, which would only make sense.

I myself have recently installed Wamp in one my machines a few weeks ago and was faced with the very same issue, yet I quickly remedied the situation by simply changing all instances of mysql_ to mysqli_ and setting the DB connection variable as the first parameter.

For example and taken from http://php.net/manual/en/function.mysqli-connect.php

$result = mysqli_query($link, $query); // $link being the connection variable

This is what their demo SQL code looks like:

<?php 
$link = mysql_connect('hostname','dbuser','dbpassword'); 
if (!$link) { 
    die('Could not connect to MySQL: ' . mysql_error()); 
} 
echo 'Connection OK'; mysql_close($link); 
?>

Change it to the following as an example and changing the proper code for your own DB:

<?php 
$link = mysqli_connect('hostname','dbuser','dbpassword','db_name'); 
if (!$link) { 
    die('Could not connect to MySQL: ' . mysqli_error($link)); 
} 
echo 'Connection OK'; mysqli_close($link); 
?>

For more information on mysqli_ and PDO, visit the following pages:

Additional links:

which are much better and safer to use when getting into database work.

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
  • @user2308205 You asked quite a few questions and have not accepted any of them. This one for example http://stackoverflow.com/q/16505715/ where the answer given resolved the problem (*" Done ...its works .. thanks alot bro .. :D – user2308205 May 12 '13 at 10:07 "*). You need to accept answers **including mine here**. If you don't, then others may not want to help you again, including myself. Your questions may eventually get flagged and we wouldn't want that. – Funk Forty Niner Nov 02 '14 at 19:57
1

Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in C:\wamp\www\gazal156\system\database\mysql.php on line 6

  1. I m use opencart 1.5.6 but run open cart site then show error.
  2. Error in the simple solution.

../system/database/mysql.php

Top add line after

error_reporting(E_ALL ^ E_DEPRECATED);

and save

  • 2
    This answer is very difficult to understand and doesn't really answer the question (you just suggest hiding `DEPRECATED` errors). – Jon Surrell Feb 13 '15 at 08:30