* modified the sql factory and null sql to fail gracefully on db problems
[vsc.git] / _res / _libs / sqlfactory.class.php
blobb4256ea25d0c0c631be91a448bfe78523ef68b47
1 <?php
2 /**
3 * Factory class for data objects
4 */
6 class sqlFactory {
7 static public $TYPES = array ('postgresql', 'mysql','mysqli');
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($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 interfaceSql
30 static public function connect($incString) {
31 if (!sqlFactory::validType ($incString)) {
32 sqlFactory::$instance = new nullSql();
35 if(!(sqlFactory::$instance instanceof interfaceSql)) {
36 if (stristr($incString, 'mysqli')) {
37 sqlFactory::$instance = new mySqlIm ();
38 } elseif (stristr ($incString, 'mysql')) {
39 sqlFactory::$instance = new mySql ();
40 } elseif (stristr ($incString, 'postgresql')) {
41 sqlFactory::$instance = new nullSql (); // postgresql not implemented
42 } elseif (stristr ($incString, 'sqlserv')) {
43 sqlFactory::$instance = new nullSql (); // Sql server not implemented
46 if (sqlFactory::$instance->error) {
47 sqlFactory::$instance = new nullSql ();
50 return sqlFactory::$instance;