Access denied for user ”@’localhost’ to database ?? – PHP

  php

Q(Question):

hi guys

i have one error in php that coneect to the mysql database

the conecction is ok

but the selected the database is not work

the erorr is( Access denied for user ”@’localhost’ to database )

<?php
$link = mysql_connect('localhost', '', '');
if (!$link) {
die('Not connected : ' . mysql_error());
}
// make aaa the current db
$db_selected = mysql_select_db('amal', $link);
if (!$db_selected) {
die ('Can\'t use amal : ' . mysql_error());
}
?>

so plz anyone help me

A(Answer):

I doubt that the connection is OK, since you get an Access Denied error, which is a typical connection error. you should pass an existing login name, an empty string is unlikely to work.

A(Answer):

If you are trying to use the MySQL connection settings specified in the php.ini, you should omit the parameters to the mysql_connect altogether and let it fetch the defaults from php.ini

Otherwise like Dormilich said, you must specify the MySQL Username, and the matching Password.

A(Answer):

Try to use this

mysql_connect("ip_address","username","password") or die("could not connected".mysql_error());

mysql_select_db("databasename") or die(mysql_error());

A(Answer):

try this:


$con = mysql_connect('hostname/ip-address', 'db_username','db_password') or die('could not connect to database'. mysql_error());
mysql_select_db('db_name', $con) or die('database not selected'. mysql_error());

A(Answer):

If you are developing locally using xampp or a similar product the default user is ‘root’ and the default password is ”.

A(Answer):

@JKing

Yay! Thanks for mentioning the default user and password. I got it working now 🙂

LEAVE A COMMENT