0

I need help with problem that appear on my website while I tried to connect to mysql. so, this is the 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\sites\mysite\core\connection.php on line 9

Call Stack

    Time    Memory  Function    Location
1   0.0007  163008  {main}( )   ..\index.php:0
2   0.0012  165376  include( 'C:\wamp\www\sites\mysite\core\connection.php')    ..\index.php:1
3   0.0015  166400  mysql_connect ( )   ..\connection.php:9
( ! ) Warning: mysql_connect(): in C:\wamp\www\sites\mysite\core\connection.php on line 9
Call Stack
    Time    Memory  Function    Location
1   0.0007  163008  {main}( )   ..\index.php:0
2   0.0012  165376  include( 'C:\wamp\www\sites\mysite\core\connection.php')    ..\index.php:1
3   0.0015  166400  mysql_connect ( )   ..\connection.php:9
MySQL Error: Accטs refusי pour l'utilisateur: 'root'@'@localhost' (mot de passe: OUI)

the php code to connect that I wrote, is:

<?php
session_start();

$dbhost = "localhost"; 
$dbname = "users"; 
$dbuser = "root"; 
$dbpass = "root"; 
mysql_connect($dbhost, $dbuser, $dbpass) or die("MySQL Error: " . mysql_error());
mysql_select_db($dbname) or die("MySQL Error: " . mysql_error());
?>
Cœur
  • 37,241
  • 25
  • 195
  • 267
  • 6
    `The mysql extension is deprecated and will be removed in the future` – Rakesh Sharma Feb 02 '15 at 09:17
  • 1
    "Accטs refusי pour l'utilisateur: 'root'@'@localhost' (mot de passe: OUI)" — You got the username and/or password wrong. – Quentin Feb 02 '15 at 09:18
  • @RakeshSharma and Johnny Vega - I combined your answers, both of them, and it succeed, but the only problem is, I'm connecting to the mysql without password. that's not a big deal, but the most important thing is, that you guys solved my problem THANKS! –  Feb 02 '15 at 09:48

4 Answers4

1

cause you are using deprecated extension so Use mysqli or PDO (The mysql extension is deprecated) try

mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);
Rakesh Sharma
  • 13,680
  • 5
  • 37
  • 44
0

By default, your MySQL credentials for WAMP are:

username: root and no password.

$dbhost = "localhost"; $dbname = "users"; $dbuser = "root"; $dbpass = "";

And as other users mentioned, try to use mysqli or pdo as mysql is deprecated, but it's not your issue here.

Good luck!

Ralph Melhem
  • 767
  • 5
  • 12
  • If you have changed your root password, refer to this question: http://stackoverflow.com/questions/22724808/phpmyadmin-in-wamp-error-1045-need-to-reset-password, to revert your change or fix it. – Ralph Melhem Feb 02 '15 at 09:44
-1

If your using the default user of phpmyadmin and didn't set a new password than the password would be an empty string (no password), unless you set your password to root. Your code is correct, although you should look into mysqli when you feel like you can handle it.

  • I actually tried to do that and I saw that I don't have a password, and I gave one - "root", now phpmyadmin locked me out –  Feb 02 '15 at 09:33
  • RakeshSharma and @Johnny Vega - I combined your answers, both of them, and it succeed, but the only problem is, I'm connecting to the mysql without password. that's not a big deal, but the most important thing is, that you guys solved my problem THANKS! –  Feb 02 '15 at 09:48
-1

mysql_connect — Open a connection to a MySQL Server. This extension was deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0. Instead, the MySQLi or PDO_MySQL extension should be used. See also MySQL: choosing an API guide and related FAQ for more information. Alternatives to this function include:

mysqli_connect()
PDO::__construct()
KernelPanic
  • 2,328
  • 7
  • 47
  • 90