Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

SQLSTATE[HY000] [1045] Access denied for user ''@'localhost' !!!

hello there.

I have finished my dataBase then I typed the code to connect to the dataBase through using PDO and I include (by include 'connect.php') that file in my index.php. when I try to see the result I have this error :-

" fail :(! SQLSTATE[HY000] [1045] Access denied for user ''@'localhost' (using password: YES) "

This is the Code that I type it to connect to dataBase:-

'SET NAMES utf8');

try{ $con=new PDO($dsn,$pass,$user,$option); $con>setAttribute (PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION); echo "great!"; }

catch(PDOException $e) { echo "fail :(! ". $e->getMessage();} ?>

I have seen heaps of videos on youTube and most of them was edition in "config.Ini.Php" !

Also, if I try to do some codes on CMD rather than phpMyAdmin it don't work...like the following

"after I type mysql -u root; " THEN it show me the welcome screen....!!

but if I type "show DATABASES;" THEN I only got one one result "information_schema" !!

and if I type "CREATE DATABASE PHP;" THEN the result is "access denied for user ' ' @' localhost' to database PHP !! I really don't know what to do and what's going on . please help me in this. MOST IMPORTANT FOR ME IS SOLVE PROBLEM OF THE CONNECTION TO DATABASE

if you guys support through skype then TeamViewr that would be helpful !

I looking forward to hear from you !

5 Answers

Patrik Horváth
Patrik Horváth
11,110 Points

and have you tryed this in bash ? if u in mysql type "exit"

mysql -u root -p

or just simple you need setup root account

mysqladmin -u root password 'root password goes here'

then

mysql -h localhost -u root -p

Hi brother thanks for your help. I just try your code but not working (( Please please you seem expert. I am little junior. Do u mind please do this over team viewer

Patrik Horváth
Patrik Horváth
11,110 Points

ehmn and whot about installing XAMP then just START MySQL server and all is done :) its more simple for you :) try it :)

thank you. although i done this many times but i am doing this currently. i will update you

Patrik Horváth
Patrik Horváth
11,110 Points

:) oke, and try post comment and no whole new Answere :D

thank you bro for trying help me ...but no result same f* error :(
I feel so bad because i can't continue my project

Patrik Horváth
Patrik Horváth
11,110 Points

send me on my facebook your TeamViever ( click here on my profile and you will see facebook Icon )

thx bro i just text u now on facebook