I have various parts of my code that require me to check if a mysql connection is already established. Below i'm using if(self::$connection)
, but self::connection
seems to always return "Resource id #6" rather than boolean - what am i doing wrong?
class mysql_lib{
static $connection;
static function connect($user = FALSE){
if(!$user){
$user = 'mr_update';
}
$password = 'some_password';
self::$connection = mysql_connect('localhost', $user, $password, TRUE);
mysql_select_db('codlife_headfirst2');
}
static function disconnect(){
mysql_close(self::$connection);
}
static function mres($str){
if(!self::$connection){
self::connect('mres');
$str = mysql_real_escape_string($str);
mysql_close(self::$connection);
}
else{
$str = mysql_real_escape_string($str);
}
return $str;
}
...
thanks!
my solution : make $connection false again on disconnection...
static function disconnect(){
mysql_close(self::$connection);
self::$connection = FALSE;
}