View Full Version : mysql_connect Access Denied

08-04-2011, 07:41 AM
So I'm testing out a page on a hosted server. However they're technical help so far has just assumed it to be a coding error and so far unhelpful.

It's pretty simple, I just can't get mysql_connect() to work. The exact error I get in the log is this:

[04-Aug-2011 00:06:02] PHP Warning: mysql_connect() [<a href='function.mysql-connect'>function.mysql-connect</a>]: Access denied for user 'rtechnix'@'localhost' (using password: NO) in /home/rtechnix/protected/DbConnect.php on line 12

The exact code being referenced is below with line-12 bolded:

class Db {

protected static $server = 'localhost';
protected static $username = 'rtechnix_admin';
protected static $password = '*****';

public static function connect() {
if(!isset($dbconn)) {
global $dbconn;
$dbconn = mysql_connect($server, $username, $password) or die ('Error connecting to database.');

The username and password (obviously edited out here) are EXACTLY as they appear and were created in the cPanel Database manager. I cannot for the life of me figure out how to fix this. I'm scared this may be a mysql issue that I don't have access to fix with the hosting company and since they're being somewhat useless right now..

Thanks in advance.

08-04-2011, 08:29 AM
$dbconn = mysql_connect($server, $username, $password) or die ('Error connecting to database.');
Shouldn't that be

$dbconn = mysql_connect($this->server, $this->username, $this->password) or die ('Error connecting to database.');

08-04-2011, 04:38 PM
This part of the error message:
(using password: NO)

means that the password is not being sent through correctly, it isn't the wrong password, just no password is being sent.