Mysql Connection Failure
Posted: Sun Jul 24, 2011 3:37 am
Hi,
I'm a newbie to php, what's suppose to happen when the main page loads is a connection is to be made to the database server. The issue is it doesn't happen, $link returns null causing the connection not to be established. What am I missing that is making the connection fail?
These are functions part of a class
This is what the code is returning.
I'm a newbie to php, what's suppose to happen when the main page loads is a connection is to be made to the database server. The issue is it doesn't happen, $link returns null causing the connection not to be established. What am I missing that is making the connection fail?
These are functions part of a class
Code: Select all
/**
* Constructor
*
* @param string $host MySQL host address
* @param string $user Database user
* @param string $pass Database password
* @param string $db_name Database name
* @param boolean $persistant Is persistant connection
* @param boolean $connect_now Connect now
* @return void
*/
public function __construct($host, $user, $pass, $db_name, $persistant = true, $connect_now = true)
{
$this->host = $host; // Host address
$this->user = $user; // User
$this->pass = $pass; // Password
$this->db_name = $db_name; // Database
if ($connect_now)
$this->connect($persistant);
return;
}
/**
* Connect to the database
*
* @param boolean $persist Is persistant connection
* @return boolean
*/
public function connect($persist)
{
if ($persist)
$link = @mysql_pconnect($this->host, $this->user, $this->pass);
else
$link = @mysql_connect($this->host, $this->user, $this->pass);
//if (!$link)
//trigger_error('Could not connect to the database.', E_USER_ERROR);
if ($link)
{
$this->link = $link;
if ( @mysql_select_db($this->db_name, $link))
return true;
}
return false;
}
Code: Select all
object(MySQLAdap)#2 (6) { ["host":"MySQLAdap":private]=> string(15) "192.168.1.1" ["user":"MySQLAdap":private]=> string(4) "user" ["pass":"MySQLAdap":private]=> string(8) "password" ["db_name":"MySQLAdap":private]=> string(8) "database" ["link":"MySQLAdap":private]=> NULL ["result":"MySQLAdap":private]=> NULL }