10 defined(
'JPATH_PLATFORM') or die;
27 private static $_instance = null;
46 public function getDriver($name =
'mysqli', $options = array())
49 $options[
'driver'] = preg_replace(
'/[^A-Z0-9_\.-]/i',
'', $name);
50 $options[
'database'] = (isset($options[
'database'])) ? $options[
'database'] : null;
51 $options[
'select'] = (isset($options[
'select'])) ? $options[
'select'] :
true;
54 $class =
'JDatabaseDriver' . ucfirst(strtolower($options[
'driver']));
57 if (!class_exists($class))
59 throw new RuntimeException(sprintf(
'Unable to load Database Driver: %s', $options[
'driver']));
65 $instance =
new $class($options);
67 catch (RuntimeException $e)
69 throw new RuntimeException(sprintf(
'Unable to connect to the Database: %s', $e->getMessage()));
89 $class =
'JDatabaseExporter' . ucfirst(strtolower($name));
92 if (!class_exists($class))
95 throw new RuntimeException(
'Database Exporter not found.');
122 $class =
'JDatabaseImporter' . ucfirst(strtolower($name));
125 if (!class_exists($class))
128 throw new RuntimeException(
'Database importer not found.');
148 public static function getInstance()
150 return self::$_instance ? self::$_instance :
new JDatabaseFactory;
167 $class =
'JDatabaseQuery' . ucfirst(strtolower($name));
170 if (!class_exists($class))
173 throw new RuntimeException(
'Database Query class not found');
176 return new $class($db);
188 public static function setInstance(JDatabaseFactory $instance = null)
190 self::$_instance = $instance;