Het is een begin van mijn database class en natuurlijk even net als we zijn begonnen door de andere OO'ers hier laten raten:
PHP
<?php
/**
* @author Patrick rennings
* @copyright 2010
*/
Class Database {
protected $_connect;
protected static $_connection_type;
public function __construct ( $hostname, $username, $password = null, $database, $ctype )
{
if ( !is_int ( $ctype ) )
{
throw new exception ( ' Connection type is not an integer. (Line 17) ' );
}
elseif ( $ctype != 1 OR $ctype != 2 )
{
throw new exception ( ' Connection type is not correct. (Line 22) ' );
}
elseif ( !is_string ( $hostname ) OR !is_string ( $username ) OR !is_string($datbase) )
{
throw new exception ( ' Connection parameters arnt integers (Line 26) ' );
}
else
{
self::$_connection_type = $ctype;
if ( self::$_connection_type == 1 )
{
$this->_connect = mysql_connect( $hostname, $username, $password );
if ( ! $this->_connect )
{
throw new exception ( ' SQL connection could not be established. (Line 36) ' );
}
if ( ! mysql_select_db($database, $this->_connect) )
{
throw new exception ( ' Database connection could not be established. (Line 42) ' );
}
}
if ( self::$_connection_type == 2 )
{
$this->_connect = new mysqli ( $hostname, $username, $password, $database );
if ( ! $this->_connect )
{
throw new exception ( ' SQL connection could not be established. (Line 36) ' );
}
}
}
}
public function SqlQuery ( $QryLine )
{
if ( self::$_connection_type == 1)
{
$DbQuery = mysql_query ($this->_connect, $Qryline );
if ( ! $DbQuery )
{
throw new exception ( ' Mysql error accured ' . mysql_error ( ) );
}
else
{
return $DbQuery;
}
}
if ( self::$_connection_type == 2)
{
if ( ! $DbQuery = $this->_connect->query( $QryLine ) )
{
throw new exception ( ' Mysqli error accured ' . $this->_connnect->error );
}
else
{
return $DbQuery;
}
}
}
}
?>
Toon Meer