The following function is the old way for MySQL connections
function dbconn($autoclean = false, $mysql_close = false)
{
global $mysql_host, $mysql_user, $mysql_pass, $mysql_db;
mysql_connect($mysql_host, $mysql_user, $mysql_pass);
mysql_select_db($mysql_db);
userlogin();
if ($autoclean)
register_shutdown_function("autoclean");
if ($mysql_close)
register_shutdown_function("mysql_close");
}
Well... I've been reported by my dedicated server, something like "Use Singleton because you are spamming the mysql connections", so I code a singleton class for MySQL but the spam is still there.
<?php
class mysql {
private static $instance;
private $res;
private function __construct()
{
$this->res = mysql_connect('localhost','user','password');
mysql_select_db('database', $this->res);
}
public static function getinstance() {
if(!isset(self::$instance)) {
$c = __CLASS__;
self::$instance = new $c;
}
return self::$instance;
}
public function getres() {
return $this->res;
}
}
?>
and the function ...
function dbconn($autoclean = false, $mysql_close = false, $file = '')
{
require_once("MySQL.php");
$m = mysql::getinstance();
$m->getres();
userlogin();
if ($autoclean)
register_shutdown_function("autoclean");
//if ($mysql_close)
// register_shutdown_function("mysql_close");
}
Thanks !