Any simpler / better way of making a mysql singlton db class in php?

Accordclery

New Member
Here's the one I'm using:\[code\]<?phpfinal class Database { private static $oDb; public static function init() { if(self::$oDb == NULL) { self::$oDb = mysql_connect('localhost', 'mysql_user', 'mysql_password') or die(mysql_error()); mysql_select_db('mysql_db_name', self::$oDb) or die (mysql_error());; } return self::$oDb; } public function query($sql) { return mysql_query($sql) or die(mysql_error()); }}?>\[/code\]Usage:\[code\]$oDb = Database::init();$sql = foo;$oDb->query($sql);\[/code\]Assuming that I only want it to connect and execute this one query function, are there any improvements I should make on the class? Memory or efficiency of code?Also, is there an efficient way I can get the db credentials from a config file? I know I can't use includes inside my class.
 
Back
Top