Return to Snippet

Revision: 8827
at October 9, 2008 17:43 by ghwilson4456


Updated Code
class Database 
{
	private static $instance;
	private $dbName     = "mcms";
	private $host       = "localhost";
	private $username   = "moroch";
	private $password   = "w1d33y3";
	private $connected;
	
	public function __construct()
	{
	}
	
	public static function getInstance()
	{
		if (!self::$instance)
		{
			self::$instance = new Database();
		}

		return self::$instance;
	}
	
	public function connect()
	{
		try
		{
			$this->connected = mysql_connect($this->host,$this->username,$this->password);
			if (!$this->connected)
				throw new Exception("Could not connect to MySql server.");
		}
		catch (Exception $e)
		{
			die($e->getMessage());
		}
	}
	
	public function selectDB()
	{
		mysql_select_db($this->dbName);
	}
	
	public function execute($sql)
	{
		return mysql_query($sql);
	}
}

Revision: 8826
at October 9, 2008 17:40 by ghwilson4456


Initial Code
class Database 
{
    private static $instance;
    private $dbName     = "mcms";
    private $host       = "localhost";
    private $username   = "moroch";
    private $password   = "w1d33y3";
    private $connected;
    
	public function __construct()
    {
    }
    
    public static function getInstance()
    {
        if (!self::$instance)
        {
            self::$instance = new Database();
        }

        return self::$instance;
    }
    
    public function connect()
    {
        try
        {
            $this->connected = mysql_connect($this->host,$this->username,$this->password);
            if (!$this->connected)
                throw new Exception("Could not connect to MySql server.");
        }
        catch (Exception $e)
        {
            die($e->getMessage());
        }
    }
    
    public function selectDB()
    {
    	mysql_select_db($this->dbName);
    }
    
    public function execute($sql)
    {
    	return mysql_query($sql);
    }
    
}

Initial URL

                                

Initial Description

                                

Initial Title
PureMVC Database Class

Initial Tags
mysql, database, php, textmate

Initial Language
PHP