Reputation: 1
i trying to learn php but found an issue.. im using mamp on a windows PC. and when im trying to connect my php with mysql a get this error:SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES)..... in mysql i got the info username and password are 'root', host:localhost port:8889 and this is my code..
function connectToDb()
{
try{
return new PDO('mysql:host=localhost; dbname=tutorials','root','root');
}
catch (PDOException $e){
die ($e->getMessage());
}
}
any help will be appreciate.... thanks...
Upvotes: 0
Views: 487
Reputation: 489
add port number also to your code...
mysql:host=localhost:8889
And it will look like this
function connectToDb()
{
try{
return new PDO('mysql:host=localhost:8889; dbname=tutorials','root','root');
}
catch (PDOException $e){
die ($e->getMessage());
}
}
or your credentials will be incorrect ie, try the connection with password=' '.
Upvotes: 0
Reputation: 489
Use this it will work...
$dbhost = 'localhost:3306';
$dbuser = 'guest';
$dbpass = 'guest123';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
// make the current db as your DB_Name
$db_selected = mysql_select_db('DB_Name', $conn);
Upvotes: 0