* various small changes
[vsc.git] / _res / _libs / models / sqldrivers / sqlfactory.class.php
blobc8723046a199a6cfbd7eb290a33cf7755dc4b877
1 <?php
2 /**
3 * Factory class for data objects
4 */
5 usingPackage ('coreexceptions');
6 class sqlFactory {
7 static public $TYPES = array ('postgresql', 'mysql', 'mysqli', 'null');
8 static private $instance = false;
10 /**
11 * returning if the set DB type is supported
13 * @param string $type
14 * @return bool
16 public static function validType ($type) {
17 if (in_array(strtolower($type), sqlFactory::$TYPES))
18 return true;
19 return false;
22 /**
23 * returns the cuurent instance of the DB connection
24 * or a new connection of type $incString
26 * @param string $incString
27 * @return fooSqlDriverA
30 static public function &connect($incString) {
31 if (!sqlFactory::validType ($incString)) {
32 sqlFactory::$instance = new nullSql();
33 // throw new tsExceptionUnimplemented ('The database type is invalid');
36 if(!(sqlFactory::$instance instanceof fooSqlDriverA)) {
37 if (stristr($incString, 'mysql')) {
38 sqlFactory::$instance = new mySqlIm ();
39 } /*elseif (stristr ($incString, 'mysql')) {
40 sqlFactory::$instance = new mySql ();
41 }*/ elseif (stristr ($incString, 'postgresql')) {
42 sqlFactory::$instance = new postgreSql ();
43 } elseif (stristr ($incString, 'sqlserv')) {
44 sqlFactory::$instance = new nullSql (); // Sql server not implemented
47 if (sqlFactory::$instance->error) {
48 sqlFactory::$instance = new nullSql ();
51 return sqlFactory::$instance;