Page 1 of 1

Database Connection Problem

Posted: Thu Jun 14, 2007 9:50 am
by maddenuk
I'm using a config.php file which i use in my database class to change the values however this warning...
Warning: mysql_pconnect() [function.mysql-pconnect]: Access denied for user 'nobody'@'localhost' (using password: NO) in /home/creative/public_html/demo1/classes/database.class.php on line 16
makes be believe that the functions are not picking up the values in teh config file. Could someone explain if i am not doing something right?

Thanks

Code: Select all

<?php

require ('./../config.php');
	
	
	class database
	{	
		
					
		function databaseConnection()
		{
			 global $dbhost, $dbusername, $dbpassword,$default_dbname;
			 $link_id = '';
			
			
			$link_id = mysql_pconnect($dbhost,$dbusername,$dbpassword);
			if (!$link_id){
				$MYSQL_ERRNO = 0;
				$MYSQL_ERROR = "Connection Failed to the host".$dbhost."";
				return 0;
			}
			else if (!mysql_select_db($default_dbname)){
				$MYSQL_ERRNO = mysql_errno();
				$MYSQL_ERROR = mysql_error();
				return 0;
			}
		}
} 
?>

Code: Select all

<?php 
    ob_start(); 
    session_start(); 
     

    // The $siteURL is the full URL of where the current site is... 
     
    $site = 'demo1'; 
     
     
    // Database username, host, password and name 
    $default_dbname = '*****'; 
    $dbhost = 'localhost'; 
    $dbusername = '*****'; 
    $dbpassword = '*****'; 


?>

Posted: Thu Jun 14, 2007 10:46 am
by Gente
Make sure you have an access. I you didn't change default MySQL settings try to use 'root' as username and leave password field empty

Posted: Thu Jun 14, 2007 11:44 am
by aaronhall
Global variables are icky. When you call databaseConnection, pass the config info as arguments to the method

Code: Select all

$db->databaseConnection($dbusername, $dbpassword, .....);

......

function databaseConnection($user, $pass, ....) {
    mysql_pconnect($user, $pass, ...);
}

Posted: Thu Jun 14, 2007 3:54 pm
by RobertGonzalez
I agree with arronhall. Pass the params to the class on construction or tap into some form of configuration singleton settings class.