You are here

function DB::factory in Flickr API 5

Create a new DB object for the specified database type but don't connect to the database

Parameters

string $type the database type (eg "mysql"):

array $options an associative array of option names and values:

Return value

object a new DB object. A DB_Error object on failure.

See also

DB_common::setOption()

File

phpFlickr/PEAR/DB.php, line 446

Class

DB
Database independent query interface

Code

function &factory($type, $options = false) {
  if (!is_array($options)) {
    $options = array(
      'persistent' => $options,
    );
  }
  if (isset($options['debug']) && $options['debug'] >= 2) {

    // expose php errors with sufficient debug level
    include_once "DB/{$type}.php";
  }
  else {
    @(include_once "DB/{$type}.php");
  }
  $classname = "DB_{$type}";
  if (!class_exists($classname)) {
    $tmp = PEAR::raiseError(null, DB_ERROR_NOT_FOUND, null, null, "Unable to include the DB/{$type}.php" . " file for '{$dsn}'", 'DB_Error', true);
    return $tmp;
  }
  @($obj =& new $classname());
  foreach ($options as $option => $value) {
    $test = $obj
      ->setOption($option, $value);
    if (DB::isError($test)) {
      return $test;
    }
  }
  return $obj;
}