PDA

Click to See Complete Forum and Search --> : Singelton MySQL DB Connect Class Issue


xxarmoxx
May 13th, 2009, 03:25 PM
Hello, here is my current Singelton MySQL DB Connect Class:



<?php

// this is a singelton database connect class

class dbconnect {


// Store the single instance of Database
private static $m_pInstance;

private function __construct() {

// *** Database Connect ***
$dblink = mysql_connect('localhost', 'root', 'pwd') OR die(mysql_error());

$m_pInstance = mysql_select_db("mydb") or die(mysql_error());


}


private function __clone() {




}




public static function getInstance()
{
if (!self::$m_pInstance)
{
self::$m_pInstance = new dbconnect();
}

return self::$m_pInstance;
}





}



?>




This singelton class works fine when I use SELECT statments in another class, but it doesn't work when I am trying to use INSERT statements. When I do an insert statement I get a mysql_query(): supplied argument is not a valid MySQL-Link resource error. Any ideas on whats wrong?