/** * Constructs a handler object from the parameters $dbParams. * * Supported database parameters are: * - dbname|database: Database name * - user|username: Database user name * - pass|password: Database user password * - host|hostspec: Name of the host database is running on * - port: TCP port * * @throws ezcDbMissingParameterException if the database name was not specified. * @param array $dbParams Database connection parameters (key=>value pairs). */ public function __construct($dbParams) { $database = null; $charset = null; $host = null; $port = null; $socket = null; foreach ($dbParams as $key => $val) { switch ($key) { case 'database': case 'dbname': $database = $val; break; case 'host': case 'hostspec': $host = $val; break; case 'port': $port = $val; break; } } if (!isset($database)) { throw new ezcDbMissingParameterException('database', 'dbParams'); } $dsn = "pgsql:dbname={$database}"; if (isset($host) && $host) { $dsn .= " host={$host}"; } if (isset($port) && $port) { $dsn .= " port={$port}"; } parent::__construct($dbParams, $dsn); }
/** * Constructs a handler object from the parameters $dbParams. * * Supported database parameters are: * - dbname|database: Database name * - port: If "memory" is used then the driver will use an * in-memory database, and the database name is ignored. * * @throws ezcDbMissingParameterException if the database name was not specified. * @param array $dbParams Database connection parameters (key=>value pairs). */ public function __construct($dbParams) { $database = false; foreach ($dbParams as $key => $val) { switch ($key) { case 'database': case 'dbname': $database = $val; if (!empty($database) && $database[0] != '/' && ezcBaseFeatures::os() != 'Windows') { $database = '/' . $database; } break; } } // If the "port" is set then we use "sqlite::memory:" as DSN, otherwise we fallback // to the database name. if (!empty($dbParams['port']) && $dbParams['port'] == 'memory') { $dsn = "sqlite::memory:"; } else { if ($database === false) { throw new ezcDbMissingParameterException('database', 'dbParams'); } $dsn = "sqlite:{$database}"; } parent::__construct($dbParams, $dsn); /* Register PHP implementations of missing functions in SQLite */ $this->sqliteCreateFunction('md5', array('ezcQuerySqliteFunctions', 'md5Impl'), 1); $this->sqliteCreateFunction('mod', array('ezcQuerySqliteFunctions', 'modImpl'), 2); $this->sqliteCreateFunction('locate', array('ezcQuerySqliteFunctions', 'positionImpl'), 2); $this->sqliteCreateFunction('floor', array('ezcQuerySqliteFunctions', 'floorImpl'), 1); $this->sqliteCreateFunction('ceil', array('ezcQuerySqliteFunctions', 'ceilImpl'), 1); $this->sqliteCreateFunction('concat', array('ezcQuerySqliteFunctions', 'concatImpl')); $this->sqliteCreateFunction('toUnixTimestamp', array('ezcQuerySqliteFunctions', 'toUnixTimestampImpl'), 1); $this->sqliteCreateFunction('now', 'time', 0); }
/** * Constructs a handler object from the parameters $dbParams. * * Supported database parameters are: * - dbname|database: Database name * - user|username: Database user name * - pass|password: Database user password * - charset: Client character set * * @param array $dbParams Database connection parameters (key=>value pairs). * @throws ezcDbMissingParameterException if the database name was not specified. */ public function __construct($dbParams) { if ($dbParams instanceof PDO) { parent::__construct($dbParams); return; } $database = null; $charset = null; foreach ($dbParams as $key => $val) { switch ($key) { case 'database': case 'dbname': $database = $val; break; case 'charset': $charset = $val; break; } } if (!isset($database)) { throw new ezcDbMissingParameterException('database', 'dbParams'); } $dsn = "oci:dbname={$database}"; if (isset($charset) && $charset) { $dsn .= ";charset={$charset}"; } $db = parent::createPDO($dbParams, $dsn); parent::__construct($db); }
/** * Constructs a handler object from the parameters $dbParams. * * Supported database parameters are: * - dbname|database: Database name * - host|hostspec: Name of the host database is running on * - port: TCP port * - user|username: Database user name * - pass|password: Database user password * * @param mixed $dbParams Database connection parameters (key=>value pairs). * @throws ezcDbMissingParameterException if the database name was not specified. */ public function __construct($dbParams) { if ($dbParams instanceof PDO) { parent::__construct($dbParams); return; } $database = null; $host = null; $port = null; foreach ($dbParams as $key => $val) { switch ($key) { case 'database': case 'dbname': $database = $val; break; case 'host': case 'hostspec': $host = $val; break; case 'port': $port = $val; break; } } if (!isset($database)) { throw new ezcDbMissingParameterException('database', 'dbParams'); } if (ezcBaseFeatures::os() === 'Windows') { $dsn = "mssql:dbname={$database}"; } else { // uses FreeTDS $dsn = "dblib:dbname={$database}"; } if (isset($host) && $host) { $dsn .= ";host={$host}"; if (isset($port) && $port) { $dsn .= ":{$port}"; } } $db = parent::createPDO($dbParams, $dsn); parent::__construct($db); // setup options $this->setOptions(new ezcDbMssqlOptions()); }
/** * Constructs a handler object from the parameters $dbParams. * * Supported database parameters are: * - dbname|database: Database name * - user|username: Database user name * - pass|password: Database user password * - host|hostspec: Name of the host database is running on * - port: TCP port * - charset: Client character set * - socket: UNIX socket path * * @throws ezcDbMissingParameterException if the database name was not specified. * @param array $dbParams Database connection parameters (key=>value pairs). */ public function __construct($dbParams) { if ($dbParams instanceof PDO) { parent::__construct($dbParams); return; } $database = null; $charset = null; $host = null; $port = null; $socket = null; foreach ($dbParams as $key => $val) { switch ($key) { case 'database': case 'dbname': $database = $val; break; case 'charset': $charset = $val; break; case 'host': case 'hostspec': $host = $val; break; case 'port': $port = $val; break; case 'socket': $socket = $val; break; } } if (!isset($database)) { throw new ezcDbMissingParameterException('database', 'dbParams'); } $dsn = "mysql:dbname={$database}"; if (isset($host) && $host) { $dsn .= ";host={$host}"; } if (isset($port) && $port) { $dsn .= ";port={$port}"; } if (isset($charset) && $charset) { $dsn .= ";charset={$charset}"; } if (isset($socket) && $socket) { $dsn .= ";unix_socket={$socket}"; } $db = parent::createPDO($dbParams, $dsn); parent::__construct($db); }