I have different parts of my code that require me to check if a mysql connection is established. Below I use if(self::$connection), but self::connectionit always seems to return “Resource Identifier # 6” and not 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;
}
...
thank!
my solution : disconnect $ connection false again when disconnected ...
static function disconnect(){
mysql_close(self::$connection);
self::$connection = FALSE;
}
source
share