Source for file Ethna_DB_ADOdb.php
Documentation is available at Ethna_DB_ADOdb.php
// vim: foldmethod=marker
* @author halt feits <halt.feits@gmail.com>
define('ADODB_OUTP', 'ethna_adodb_logger'); //disable output error
require_once 'adodb/adodb.inc.php';
$logger =
& $c->getLogger();
* EthnaのフレームワークでADOdbオブジェクトを扱うための抽象クラス
* @author halt feits <halt.feits@gmail.com>
/** @var object DB DBオブジェクト */
* @param object Ethna_Controller &$controller コントローラオブジェクト
* @param bool $persistent 持続接続設定
parent::Ethna_DB($controller, $dsn, $persistent);
$this->logger =
& $controller->getLogger();
* @return mixed 0:正常終了 Ethna_Error:エラー
if ($dsn['phptype'] ==
'sqlite') {
$path =
$dsn['database'];
$this->db =
ADONewConnection("sqlite");
$this->db->Connect($path);
$this->db =
ADONewConnection($this->dsn);
$this->db->SetFetchMode(ADODB_FETCH_ASSOC);
* @return bool true:正常(接続済み) false:エラー/未接続
* @return mixed 0:正常終了 Ethna_Error:エラー
return $this->db->BeginTrans();
* @return mixed 0:正常終了 Ethna_Error:エラー
$this->db->RollbackTrans();
* @return mixed 0:正常終了 Ethna_Error:エラー
$this->db->CommitTrans();
* @param string $query SQL文
* @return mixed DB_Result:結果オブジェクト Ethna_Error:エラー
function &query($query, $inputarr =
false)
return $this->_query($query, $inputarr);
* @param string $query SQL文
* @return mixed DB_Result:結果オブジェクト Ethna_Error:エラー
function &_query($query, $inputarr =
false)
$this->logger->log(LOG_DEBUG, $query);
$r =
& $this->db->execute($query, $inputarr);
function getAll($query, $inputarr =
false)
$this->db->SetFetchMode(ADODB_FETCH_ASSOC);
return $this->db->getAll($query, $inputarr);
function getOne($query, $inputarr =
false)
return $this->db->GetOne($query, $inputarr);
function getRow($query, $inputarr =
false)
return $this->db->GetRow($query, $inputarr);
function getCol($query, $inputarr =
false)
return $this->db->GetCol($query, $inputarr);
function execute($query, $inputarr =
false)
return $this->db->Execute($query, $inputarr);
function replace($table, $arrFields, $keyCols, $autoQuote =
false)
return $this->db->Replace($table, $arrFields, $keyCols, $autoQuote);
function autoExecute($table, $fields, $mode, $where =
false, $forceUpdate =
true, $magicq =
false)
return $this->db->AutoExecute($table, $fields, $mode, $where, $forceUpdate, $magicq);
function pageExecute($query, $nrows, $page, $inputarr =
false)
return $this->db->PageExecute($query, $nrows, $page, $inputarr);
* 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:59:38 +0900 by phpDocumentor 1.4.3