tomb04 Posted February 1, 2010 Share Posted February 1, 2010 Hello, I am getting the following error message... Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[28000] [1045] Access denied for user 'root'@'localhost' (using password: YES)' in C:\xampp\htdocs\Manager.php:23 Stack trace: #0 C:\xampp\htdocs\Manager.php(23): PDO->__construct('mysql:host=loca...', 'root', 'mypassword') #1 C:\xampp\htdocs\Command_BlogIndex.php(9): Manager->__construct() #2 C:\xampp\htdocs\Command.php(14): Command_BlogIndex->doExecute(Object(Request)) #3 C:\xampp\htdocs\Controller.php(38): Command->execute(Object(Request)) #4 C:\xampp\htdocs\Controller.php(14): Controller->handleRequest() #5 C:\xampp\htdocs\index.php(5): Controller::run() #6 {main} thrown in C:\xampp\htdocs\Manager.php on line 23 When I looked at Manager.php file, line 23 there is no typo error. Line 23 reads... $pdo = new PDO($database_dsn, $database_login, $database_password); This is straight copy and paste. I am working on sample only. Not a assignment. PDO is enabled, So this has lead me to think that I have not been able to contect to the mysql db. I am using xampp (see below the version I am using) on Windows 7 64bit which I don't think is the problem. I have attached the some of the files. I think I have identified where I need to change the characters in the database dsn, username and password? Thank you Tomb Apache Friends XAMPP (Basis Package) version 1.7.3 ###### + Apache 2.2.14 (IPV6 enabled) + MySQL 5.1.41 (Community Server) with PBXT engine 1.0.09-rc + PHP 5.3.1 (PEAR, Mail_Mime, MDB2, Zend) + Perl 5.10.1 (Bundle::Apache2, Apache2::Request, Bundle::Apache::ASP, Bundle::Email, Bundle::DBD::mysql, DBD::SQlite, Randy Kobes PPM) + XAMPP Control Version 2.5.8 (ApacheFriends Edition) + XAMPP CLI Bundle 1.6 + XAMPP Port Check 1.5 + XAMPP Security 1.1 + SQLite 2.8.17 + SQLite 3.6.20 + OpenSSL 0.9.8l + phpMyAdmin 3.2.4 + ADOdb v5.10 + FPDF v1.6 + Zend Framework 1.9.6 Minimal Package (via PEAR) + Mercury Mail Transport System v4.72 + msmtp 1.4.19 (a sendmail compatible SMTP client) + FileZilla FTP Server 0.9.33 + Webalizer 2.21-02 (with GeoIP lite) + apc 3.1.3p1 for PHP + eAccelerator 0.9.6-rc1 for PHP + Ming 0.4.3 for PHP + PDF with pdflib lite v7.0.4p4 for PHP + rar 2.0.0-dev for PHP + Xdebug 2.0.6-dev for PHP + libapreq2 v2.12 (mod_apreq2) for Apache [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/190586-fatal-error-uncaught-exception-pdoexception/ Share on other sites More sharing options...
gizmola Posted February 1, 2010 Share Posted February 1, 2010 It's failing to connect to the database. Check that the username and password as configured actually work. Quote Link to comment https://forums.phpfreaks.com/topic/190586-fatal-error-uncaught-exception-pdoexception/#findComment-1005179 Share on other sites More sharing options...
tomb04 Posted February 1, 2010 Author Share Posted February 1, 2010 gizmola, Do you mean through config.inc.php? I have already configured the username and password when I was reading through Peachpit Press PHP 6 and MySQL 5 for Dynamic Web Sites (which worked all well). If else were can you explain where and how? Thank you Quote Link to comment https://forums.phpfreaks.com/topic/190586-fatal-error-uncaught-exception-pdoexception/#findComment-1005199 Share on other sites More sharing options...
Andy-H Posted February 1, 2010 Share Posted February 1, 2010 Take a look on Rasmus' Toys page, http://toys.lerdorf.com/archives/50-Using-pecloauth-to-post-to-Twitter.html specifically, the fatal error method, PDO throws exceptions when it fails to connect. You need to use try-catch to catch the pdo exceptions thrown. ie try { // new PDO('connect to db'); } catch(PDOException $e) { // handle error // die($e->getmessage()); } Quote Link to comment https://forums.phpfreaks.com/topic/190586-fatal-error-uncaught-exception-pdoexception/#findComment-1005202 Share on other sites More sharing options...
gizmola Posted February 1, 2010 Share Posted February 1, 2010 gizmola, Do you mean through config.inc.php? I have already configured the username and password when I was reading through Peachpit Press PHP 6 and MySQL 5 for Dynamic Web Sites (which worked all well). If else were can you explain where and how? I don't have enough information to tell you that. What I can tell you is that the source of your problem is stated clearly in the exception stack: PDOException' with message 'SQLSTATE[28000] [1045] Access denied for user 'root'@'localhost' (using password: YES)' So apparently your configuration is attempting to connect as the mysql user 'root' using some password. In all likelyhood, the password is wrong. In general it's best to have a user specifically for the database needed by the application, but that's more an aside as it is irrelevant to the problem you are currently having. I would diagnose this using the mysql command line client in a shell, or phpMyAdmin. Regardless, this is why I stated that its's a username password issue. The only other issue would be the host, if for some reason the mysql server was on another machine, but I'm going to assume that is not your problem. Quote Link to comment https://forums.phpfreaks.com/topic/190586-fatal-error-uncaught-exception-pdoexception/#findComment-1005210 Share on other sites More sharing options...
gizmola Posted February 1, 2010 Share Posted February 1, 2010 Take a look on Rasmus' Toys page, http://toys.lerdorf.com/archives/50-Using-pecloauth-to-post-to-Twitter.html specifically, the fatal error method, PDO throws exceptions when it fails to connect. You need to use try-catch to catch the pdo exceptions thrown. ie try { // new PDO('connect to db'); } catch(PDOException $e) { // handle error // die($e->getmessage()); } Yes that's great that he can catch the exception, only to find that the page is broken because no queries work. Of course he could also print out the exception which would ultimately lead back to the real problem which is that the username/password are being rejected. Quote Link to comment https://forums.phpfreaks.com/topic/190586-fatal-error-uncaught-exception-pdoexception/#findComment-1005211 Share on other sites More sharing options...
Mchl Posted February 1, 2010 Share Posted February 1, 2010 The only other issue would be the host, if for some reason the mysql server was on another machine, but I'm going to assume that is not your problem. And error message would be different then. Quote Link to comment https://forums.phpfreaks.com/topic/190586-fatal-error-uncaught-exception-pdoexception/#findComment-1005214 Share on other sites More sharing options...
gizmola Posted February 1, 2010 Share Posted February 1, 2010 The only other issue would be the host, if for some reason the mysql server was on another machine, but I'm going to assume that is not your problem. And error message would be different then. Not necessarily. If his target server should be: somehost.com, yet there's still a mysql server running on the localhost, then the error would still indicate that the root user password was wrong. Quote Link to comment https://forums.phpfreaks.com/topic/190586-fatal-error-uncaught-exception-pdoexception/#findComment-1005222 Share on other sites More sharing options...
Mchl Posted February 1, 2010 Share Posted February 1, 2010 In this case, yes. Quote Link to comment https://forums.phpfreaks.com/topic/190586-fatal-error-uncaught-exception-pdoexception/#findComment-1005223 Share on other sites More sharing options...
tomb04 Posted February 1, 2010 Author Share Posted February 1, 2010 For some reason the password has changed now I have to figure how reset password to do this. Can this be done. The password saved in config.inc.php is not the one. I went through cmd (C:\xampp\mysql\bin\mysql -u root -p). To find out about the password. I wonder if the following has anything to do it in the phpadmin (I don't think so)... Connection for controluser as defined in your configuration failed. Quote Link to comment https://forums.phpfreaks.com/topic/190586-fatal-error-uncaught-exception-pdoexception/#findComment-1005240 Share on other sites More sharing options...
gizmola Posted February 2, 2010 Share Posted February 2, 2010 If you have the root account then you can change the password for other users. If you've lost the root password, there is a complicated process for resetting it. http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html Quote Link to comment https://forums.phpfreaks.com/topic/190586-fatal-error-uncaught-exception-pdoexception/#findComment-1005292 Share on other sites More sharing options...
tomb04 Posted February 2, 2010 Author Share Posted February 2, 2010 Actually I had the wrong password typed so pls disregard my previous notes. However I am having the following error... Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[28000] [1045] Access denied for user 'ODBC'@'localhost' (using password: NO)' in C:\xampp\htdocs\Manager.php:17 Stack trace: #0 C:\xampp\htdocs\Manager.php(17): PDO->__construct('mysql:host=loca...', NULL, NULL) #1 C:\xampp\htdocs\Command_BlogIndex.php(9): Manager->__construct() #2 C:\xampp\htdocs\Command.php(14): Command_BlogIndex->doExecute(Object(Request)) #3 C:\xampp\htdocs\Controller.php(38): Command->execute(Object(Request)) #4 C:\xampp\htdocs\Controller.php(14): Controller->handleRequest() #5 C:\xampp\htdocs\index.php(5): Controller::run() #6 {main} thrown in C:\xampp\htdocs\Manager.php on line 17 Quote Link to comment https://forums.phpfreaks.com/topic/190586-fatal-error-uncaught-exception-pdoexception/#findComment-1005404 Share on other sites More sharing options...
Mchl Posted February 2, 2010 Share Posted February 2, 2010 Now you're trying to login without username and password set. Quote Link to comment https://forums.phpfreaks.com/topic/190586-fatal-error-uncaught-exception-pdoexception/#findComment-1005414 Share on other sites More sharing options...
tomb04 Posted February 2, 2010 Author Share Posted February 2, 2010 So what you saying I got get and set wrong. Manager.php The syntax is reading... function __construct() { $database_dsn = Registry::get("database_dsn"); $database_login = Registry::get("database_login"); $databse_password = Registry::get("database_password"); $pdo = new PDO($database_dsn, $databse_user, $database_password); self::$DB = $pdo; self::$DB->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXECPTION); } function prepareStatment($stmt_s) { if(isset(self::$stmts[$stmt_s])) { return self::$stmts[stmt_s]; } $stmt_handle = self::$DB->perpare($stmt_s); self::$stmts[$stmt_s] = $stmt_handle; return $stmt_handle; } and in the controller.php the sytax is read... function init() { Registry::set("database_dsn", "mysql:host=localhost;dbname=messages"); Registry::set("database_login", "root"); Registry::set("database_password", "thepassword"); } Quote Link to comment https://forums.phpfreaks.com/topic/190586-fatal-error-uncaught-exception-pdoexception/#findComment-1005456 Share on other sites More sharing options...
Mchl Posted February 2, 2010 Share Posted February 2, 2010 Check if you're getting anything from registry function __construct() { echo $database_dsn = Registry::get("database_dsn"); echo $database_login = Registry::get("database_login"); echo $databse_password = Registry::get("database_password"); $pdo = new PDO($database_dsn, $databse_user, $database_password); self::$DB = $pdo; self::$DB->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } This should echo your database details. If it doesn't something's wrong with either your Registry() class, or init() is not called early enough to set this data for PDO Quote Link to comment https://forums.phpfreaks.com/topic/190586-fatal-error-uncaught-exception-pdoexception/#findComment-1005461 Share on other sites More sharing options...
salathe Posted February 2, 2010 Share Posted February 2, 2010 In your code you have $database_login = Registry::get("database_login"); $databse_password = Registry::get("database_password"); Note that later you use the variables $database_user and $database_password Quote Link to comment https://forums.phpfreaks.com/topic/190586-fatal-error-uncaught-exception-pdoexception/#findComment-1005465 Share on other sites More sharing options...
tomb04 Posted February 2, 2010 Author Share Posted February 2, 2010 Request.php is showing blank page. I have created tables fields are id, title, message, date_added. But no there is no data in the field. So you reckon there is something wrong with Registry() class. class Registry { private static $values = array(); static function set($key, $val) { self::$values[$key] = $val; } static function get($key) { if(isset(self::$values[$key])) { return self::$values[$key]; } return null; } } I have ammended typo errors and the error is now showing... Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000] [1049] Unknown database 'messages'' in C:\xampp\htdocs\Manager.php:17 Stack trace: #0 C:\xampp\htdocs\Manager.php(17): PDO->__construct('mysql:host=loca...', 'root', 'thepassword') #1 C:\xampp\htdocs\Command_BlogIndex.php(9): Manager->__construct() #2 C:\xampp\htdocs\Command.php(14): Command_BlogIndex->doExecute(Object(Request)) #3 C:\xampp\htdocs\Controller.php(38): Command->execute(Object(Request)) #4 C:\xampp\htdocs\Controller.php(14): Controller->handleRequest() #5 C:\xampp\htdocs\index.php(5): Controller::run() #6 {main} thrown in C:\xampp\htdocs\Manager.php on line 17 Unknown database 'messages'' -- Is it saying that there is no database called messages? When I have created messages table in phpmyadmin. The sample I am working on is based on linux. Has this got anything to do with it. Quote Link to comment https://forums.phpfreaks.com/topic/190586-fatal-error-uncaught-exception-pdoexception/#findComment-1005560 Share on other sites More sharing options...
Mchl Posted February 2, 2010 Share Posted February 2, 2010 database != table When you go to phpMyAdmin's main page you can click 'databases' tab on top, to see databases created on your server. Tables are stored within databases. Quote Link to comment https://forums.phpfreaks.com/topic/190586-fatal-error-uncaught-exception-pdoexception/#findComment-1005573 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.