Source for file DB.php
Documentation is available at DB.php
// vim: foldmethod=marker
* @author Masaki Fujimoto <fujimoto@php.net>
* @license http://www.opensource.org/licenses/bsd-license.php The BSD License
* @version $Id: bc26055c2e52c8ef683e4a50b33b3fa9dd41a345 $
* EthnaのフレームワークでDBオブジェクトを扱うための抽象クラス
* @author Masaki Fujimoto <fujimoto@php.net>
* @XXX stay public because of B.C.
* @protected object DB DBオブジェクト
/** @protected array トランザクション管理スタック */
* @param object Ethna_Controller $controller コントローラオブジェクト
* @param bool $persistent 持続接続設定
public function __construct($controller, $dsn, $persistent)
$this->persistent =
$persistent;
* @return mixed 0:正常終了 Ethna_Error:エラー
* @return bool true:正常(接続済み) false:エラー/未接続
* @return mixed 0:正常終了 Ethna_Error:エラー
* @return mixed 0:正常終了 Ethna_Error:エラー
* @return mixed 0:正常終了 Ethna_Error:エラー
* @return mixed array: PEAR::DBに準じたメタデータ
* Parse a data source name
* Additional keys can be added by appending a URI query string to the
* The format of the supplied DSN is in its fullest form:
* phptype(dbsyntax)://username:password@protocol+hostspec/database?option=8&another=true
* Most variations are allowed:
* phptype://username:password@protocol+hostspec:110//usr/db_file.db?mode=0644
* phptype://username:password@hostspec/database_name
* phptype://username:password@hostspec
* phptype://username@hostspec
* phptype://hostspec/database
* @param string $dsn Data Source Name to be parsed
* @return array an associative array with the following keys:
* + phptype: Database backend used in PHP (mysql, odbc etc.)
* + dbsyntax: Database used with regards to SQL syntax etc.
* + protocol: Communication protocol to use (tcp, unix etc.)
* + hostspec: Host specification (hostname[:port])
* + database: Database to use on the DBMS server
* + username: User name for login
* + password: Password for login
$dsn['dbsyntax'] =
$dsn['phptype'];
// Find phptype and dbsyntax
if (($pos =
strpos($dsn, '://')) !==
false) {
$dsn =
substr($dsn, $pos +
3);
// Get phptype and dbsyntax
// $str => phptype(dbsyntax)
if (preg_match('|^(.+?)\((.*?)\)$|', $str, $arr)) {
$parsed['phptype'] =
$arr[1];
$parsed['dbsyntax'] =
!$arr[2] ?
$arr[1] :
$arr[2];
$parsed['phptype'] =
$str;
$parsed['dbsyntax'] =
$str;
// Get (if found): username and password
// $dsn => username:password@protocol+hostspec/database
if (($at =
strrpos($dsn, '@')) !==
false) {
if (($pos =
strpos($str, ':')) !==
false) {
// Find protocol and hostspec
if (preg_match('|^([^(]+)\((.*?)\)/?(.*?)$|', $dsn, $match)) {
// $dsn => proto(proto_opts)/database
$proto_opts =
$match[2] ?
$match[2] :
false;
// $dsn => protocol+hostspec/database (old format)
if (strpos($dsn, '+') !==
false) {
list
($proto, $dsn) =
explode('+', $dsn, 2);
if (strpos($dsn, '/') !==
false) {
list
($proto_opts, $dsn) =
explode('/', $dsn, 2);
// process the different protocol options
$parsed['protocol'] =
(!empty($proto)) ?
$proto :
'tcp';
if ($parsed['protocol'] ==
'tcp') {
if (strpos($proto_opts, ':') !==
false) {
list
($parsed['hostspec'], $parsed['port']) =
explode(':', $proto_opts);
$parsed['hostspec'] =
$proto_opts;
} elseif ($parsed['protocol'] ==
'unix') {
$parsed['socket'] =
$proto_opts;
if (($pos =
strpos($dsn, '?')) ===
false) {
// /database?param1=value1¶m2=value2
$dsn =
substr($dsn, $pos +
1);
if (strpos($dsn, '&') !==
false) {
} else { // database?param1=value1
foreach ($opts as $opt) {
list
($key, $value) =
explode('=', $opt);
if (!isset
($parsed[$key])) {
// don't allow params overwrite
Documentation generated on Fri, 11 Nov 2011 03:57:57 +0900 by phpDocumentor 1.4.3