10 defined(
'JPATH_PLATFORM') or die;
28 public static function isSupported();
202 $connectors = array();
205 $iterator =
new DirectoryIterator(__DIR__ .
'/driver');
207 foreach ($iterator as $file)
209 $fileName = $file->getFilename();
213 if (!$file->isFile() || substr($fileName, strrpos($fileName,
'.') + 1) !=
'php')
219 $class = str_ireplace(
'.php',
'',
'JDatabaseDriver' . ucfirst(trim($fileName)));
222 if (!class_exists($class))
228 if ($class::isSupported())
231 $connectors[] = str_ireplace(
'.php',
'', $fileName);
258 $options[
'driver'] = (isset(
$options[
'driver'])) ? preg_replace(
'/[^A-Z0-9_\.-]/i',
'',
$options[
'driver']) :
'mysqli';
263 $signature = md5(serialize(
$options));
266 if (empty(self::$instances[$signature]))
270 $class =
'JDatabaseDriver' . ucfirst(strtolower(
$options[
'driver']));
273 if (!class_exists($class))
275 throw new RuntimeException(sprintf(
'Unable to load Database Driver: %s',
$options[
'driver']));
283 catch (RuntimeException $e)
285 throw new RuntimeException(sprintf(
'Unable to connect to the Database: %s', $e->getMessage()));
289 self::$instances[$signature] = $instance;
292 return self::$instances[$signature];
312 for ($i = 0; $i < $end; $i++)
314 $current = substr(
$sql, $i, 1);
316 if (($current ==
'"' || $current ==
'\''))
320 while (substr(
$sql, $i - $n + 1, 1) ==
'\\' && $n < $i)
329 if ($current == $char)
343 if (($current ==
';' && !$open) || $i == $end - 1)
345 $queries[] = substr(
$sql, $start, ($i - $start + 1));
373 return $this->
quote($args[0], isset($args[1]) ? $args[1] :
true);
376 return $this->
quoteName($args[0], isset($args[1]) ? $args[1] : null);
391 $this->_database = (isset(
$options[
'database'])) ?
$options[
'database'] :
'';
393 $this->tablePrefix = (isset(
$options[
'prefix'])) ?
$options[
'prefix'] :
'jos_';
396 $this->log = array();
414 if (is_null($dbName))
416 throw new RuntimeException(
'Database name must not be null.');
432 abstract public function connect();
460 throw new RuntimeException(
'$options object must not be null.');
464 throw new RuntimeException(
'$options object must have db_name set.');
468 throw new RuntimeException(
'$options object must have db_user set.');
496 $this->disconnectHandlers[] = $callable;
510 public abstract function dropTable($table, $ifExists =
true);
522 abstract public function escape($text, $extra =
false);
589 return 'ALTER DATABASE ' . $this->
quoteName($dbName) .
' CHARACTER SET `utf8`';
608 return 'CREATE DATABASE ' . $this->
quoteName(
$options->db_name) .
' CHARACTER SET `utf8`';
668 return 'Y-m-d H:i:s';
765 $class =
'JDatabaseExporter' . ucfirst($this->name);
768 if (!class_exists($class))
771 throw new RuntimeException(
'Database Exporter not found.');
791 $class =
'JDatabaseImporter' . ucfirst($this->name);
794 if (!class_exists($class))
797 throw new RuntimeException(
'Database Importer not found');
821 $class =
'JDatabaseQuery' . ucfirst($this->name);
824 if (!class_exists($class))
827 throw new RuntimeException(
'Database Query Class not found.');
830 return new $class($this);
852 $iteratorClass =
'JDatabaseIterator' . ucfirst($this->name);
855 if (!class_exists($iteratorClass))
858 throw new RuntimeException(sprintf(
'class *%s* is not defined', $iteratorClass));
862 return new $iteratorClass($this->
execute(), $column, $class);
922 JLog::add(
'JDatabaseDriver::getUTFSupport() is deprecated. Use JDatabaseDriver::hasUTFSupport() instead.',
JLog::WARNING,
'deprecated');
954 abstract public function insertid();
974 foreach (get_object_vars($object) as $k => $v)
977 if (is_array($v) or is_object($v) or $v === null)
990 $values[] = $this->
quote($v);
997 ->values(implode(
',', $values));
1010 if ($key && $id && is_string($key))
1012 $object->$key = $id;
1027 return version_compare($this->
getVersion(), static::$dbMinimum) >= 0;
1095 $value = ($column) ? (isset($row[$column]) ? $row[$column] : $row) : $row;
1099 $array[$row[$key]] = $value;
1160 JLog::add(__METHOD__ .
'() is deprecated. Use JDatabase::getIterator() instead.',
JLog::WARNING,
'deprecated');
1170 return $this->errorNum ? null :
false;
1198 JLog::add(
'JDatabaseDriver::loadNextRow() is deprecated. Use JDatabaseDriver::getIterator() instead.',
JLog::WARNING,
'deprecated');
1208 return $this->errorNum ? null :
false;
1291 $array[$row->$key] = $row;
1401 $array[$row[$key]] = $row;
1425 public abstract function lockTable($tableName);
1438 public function quote($text, $escape =
true)
1440 if (is_array($text))
1442 foreach ($text as $k => $v)
1444 $text[$k] = $this->
quote($v, $escape);
1451 return '\'' . ($escape ? $this->
escape($text) : $text) .
'\'';
1470 if (is_string(
$name))
1478 settype($as,
'array');
1482 return $quotedName . $quotedAs;
1490 foreach (
$name as $str)
1495 elseif (is_array(
$name) && (count(
$name) == count($as)))
1499 for ($i = 0; $i <
$count; $i++)
1523 foreach ($strArr as $part)
1530 if (strlen($q) == 1)
1532 $parts[] = $q . $part . $q;
1536 $parts[] = $q{0} . $part . $q{1};
1540 return implode(
'.', $parts);
1573 $pattern =
'/(?<=[^"\'])(' . preg_quote($prefix,
'/') .
')("(?:[^\\\\"]|\.)*"|\'(?:[^\\\\\']|\.)*\')?/';
1575 return preg_replace($pattern, $this->
getPrefix() .
'\\2',
$sql);
1591 public abstract function renameTable($oldTable, $newTable, $backup = null, $prefix = null);
1603 abstract public function select($database);
1617 $this->debug = (bool) $level;
1635 $this->sql = $query;
1643 $this->limit = (int) max(0,
$limit);
1644 $this->offset = (int) max(0,
$offset);
1657 abstract public function setUTF();
1729 if (is_string($key))
1734 if (is_object($key))
1736 $key = (array) $key;
1740 $statement =
'UPDATE ' . $this->
quoteName($table) .
' SET %s WHERE %s';
1743 foreach (get_object_vars($object) as $k => $v)
1746 if (is_array($v) or is_object($v) or $k[0] ==
'_')
1752 if (in_array($k, $key))
1775 $val = $this->
quote($v);
1779 $fields[] = $this->
quoteName($k) .
'=' . $val;
1789 $this->
setQuery(sprintf($statement, implode(
",", $fields), implode(
' AND ', $where)));
1802 abstract public function execute();