tsz Posted April 11, 2015 Share Posted April 11, 2015 Hello, I recently installed Xampp and modified it's 80 and 443 default ports into other ports. I have also set an mysql password via the Xampp localhost manager. Now, I have rote an open_connection class in order to connect to the database but I get an credential error: Warning: mysql_connect(): Access denied for user 'root'@'localhost' (using password: YES) in C:\xampp\htdocs\CMS\models\dbModel.php on line 19 failed to connect MYSQL Server. Please contact your website manager for futher assistance Here is the class I have wrote: class dbmodel{ private $connection; private $SelectDB; function __construct(){ $this->open_connection(); //$this->select_db(); } public function open_connection() { defined('DB_HOST') ? null : define('DB_HOST', 'localhost'); defined('DB_USER') ? null : define('DB_USER', 'root'); defined('DB_PASSWORD') ? null : define('DB_PASSWORD', '1234'); defined('DB_NAME') ? null : define('DB_NAME', 'cms'); $this->connection = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$this->connection) { die('failed to connect MYSQL Server. Please contact your website manager for futher assistance'); } else { $SelectDB = mysql_select_db(DB_NAME, $this->connection); if(!$SelectDB){ die("Can't Select a database"); } } } } what should i do? Is the problem in the class or in the configuration of XAMPP? Help plz. ty Quote Link to comment Share on other sites More sharing options...
requinix Posted April 11, 2015 Share Posted April 11, 2015 As you said, it's a credential error. Which means root@localhost with password "1234" was not allowed to connect. Which probably means the password is wrong. Don't use the root account to begin with. Create a new user with the permissions you need: connect as root successfully and run the query GRANT SELECT, INSERT, UPDATE, DELETE ON cms.* TO usernamegoeshere@localhost IDENTIFIED BY "password goes here"That will create a user with the common privileges; you won't be able to use it to do things like CREATE TABLEs or ALTER TABLEs, but those aren't the kinds of things you should be doing with this user anyways (temporarily use the root account for that). Then, of course, change the credentials in your code to match. Quote Link to comment 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.