Skip to content

Commit

Permalink
fix some errors
Browse files Browse the repository at this point in the history
  • Loading branch information
orbisnull committed Dec 13, 2013
1 parent 3f77d85 commit a78803c
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 300 deletions.
68 changes: 34 additions & 34 deletions src/DbSimple/Connect.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
* @method string escape(mixed $s, bool $isIdent=false)
* @method SubQuery subquery(string $query, $argOrArgsByComma)
*/
class DbSimple_Connect
class Connect
{
/** @var DbSimple_Generic_Database База данных */
protected $DbSimple;
/** @var Database База данных */
protected $dbSimple;
/** @var string DSN подключения */
protected $DSN;
protected $dsn;
/** @var string Тип базы данных */
protected $shema;
/** @var array Что выставить при коннекте */
Expand All @@ -42,8 +42,8 @@ class DbSimple_Connect
*/
public function __construct($dsn)
{
$this->DbSimple = null;
$this->DSN = $dsn;
$this->dbSimple = null;
$this->dsn = $dsn;
$this->init = array();
$this->shema = ucfirst(substr($dsn, 0, strpos($dsn, ':')));
}
Expand Down Expand Up @@ -75,9 +75,9 @@ public function getShema()
*/
public function __call($method, $params)
{
if ($this->DbSimple === null)
$this->connect($this->DSN);
return call_user_func_array(array(&$this->DbSimple, $method), $params);
if ($this->dbSimple === null)
$this->connect($this->dsn);
return call_user_func_array(array($this->dbSimple, $method), $params);
}

/**
Expand All @@ -86,11 +86,11 @@ public function __call($method, $params)
*/
public function selectPage(&$total, $query)
{
if ($this->DbSimple === null)
$this->connect($this->DSN);
if ($this->dbSimple === null)
$this->connect($this->dsn);
$args = func_get_args();
$args[0] = &$total;
return call_user_func_array(array(&$this->DbSimple, 'selectPage'), $args);
return call_user_func_array(array(&$this->dbSimple, 'selectPage'), $args);
}

/**
Expand All @@ -106,20 +106,20 @@ protected function connect($dsn)
$this->errorHandler('Невозможно загрузить драйвер базы данных', $parsed);
$this->shema = ucfirst($parsed['scheme']);
require_once dirname(__FILE__).'/'.$this->shema.'.php';
$class = 'DbSimple_'.$this->shema;
$this->DbSimple = new $class($parsed);
$this->errmsg = &$this->DbSimple->errmsg;
$this->error = &$this->DbSimple->error;
$class = $this->shema;
$this->dbSimple = new $class($parsed);
$this->errmsg = &$this->dbSimple->errmsg;
$this->error = &$this->dbSimple->error;
$prefix = isset($parsed['prefix']) ? $parsed['prefix'] : ($this->_identPrefix ? $this->_identPrefix : false);
if ($prefix)
$this->DbSimple->setIdentPrefix($prefix);
if ($this->_cachePrefix) $this->DbSimple->setCachePrefix($this->_cachePrefix);
if ($this->_cacher) $this->DbSimple->setCacher($this->_cacher);
if ($this->_logger) $this->DbSimple->setLogger($this->_logger);
$this->DbSimple->setErrorHandler($this->errorHandler!==null ? $this->errorHandler : array(&$this, 'errorHandler'));
$this->dbSimple->setIdentPrefix($prefix);
if ($this->_cachePrefix) $this->dbSimple->setCachePrefix($this->_cachePrefix);
if ($this->_cacher) $this->dbSimple->setCacher($this->_cacher);
if ($this->_logger) $this->dbSimple->setLogger($this->_logger);
$this->dbSimple->setErrorHandler($this->errorHandler!==null ? $this->errorHandler : array(&$this, 'errorHandler'));
//выставление переменных
foreach($this->init as $query)
call_user_func_array(array(&$this->DbSimple, 'query'), $query);
call_user_func_array(array($this->dbSimple, 'query'), $query);
$this->init = array();
}

Expand Down Expand Up @@ -149,8 +149,8 @@ public function errorHandler($msg, $info)
public function addInit($query)
{
$args = func_get_args();
if ($this->DbSimple !== null)
return call_user_func_array(array(&$this->DbSimple, 'query'), $args);
if ($this->dbSimple !== null)
return call_user_func_array(array(&$this->dbSimple, 'query'), $args);
$this->init[] = $args;
}

Expand All @@ -169,8 +169,8 @@ public function setErrorHandler($handler)
{
$prev = $this->errorHandler;
$this->errorHandler = $handler;
if ($this->DbSimple)
$this->DbSimple->setErrorHandler($handler);
if ($this->dbSimple)
$this->dbSimple->setErrorHandler($handler);
return $prev;
}

Expand All @@ -190,8 +190,8 @@ public function setLogger($logger)
{
$prev = $this->_logger;
$this->_logger = $logger;
if ($this->DbSimple)
$this->DbSimple->setLogger($logger);
if ($this->dbSimple)
$this->dbSimple->setLogger($logger);
return $prev;
}

Expand All @@ -204,8 +204,8 @@ public function setCacher(Zend_Cache_Backend_Interface $cacher=null)
{
$prev = $this->_cacher;
$this->_cacher = $cacher;
if ($this->DbSimple)
$this->DbSimple->setCacher($cacher);
if ($this->dbSimple)
$this->dbSimple->setCacher($cacher);
return $prev;
}

Expand All @@ -217,8 +217,8 @@ public function setIdentPrefix($prx)
{
$old = $this->_identPrefix;
if ($prx !== null) $this->_identPrefix = $prx;
if ($this->DbSimple)
$this->DbSimple->setIdentPrefix($prx);
if ($this->dbSimple)
$this->dbSimple->setIdentPrefix($prx);
return $old;
}

Expand All @@ -230,8 +230,8 @@ public function setCachePrefix($prx)
{
$old = $this->_cachePrefix;
if ($prx !== null) $this->_cachePrefix = $prx;
if ($this->DbSimple)
$this->DbSimple->setCachePrefix($prx);
if ($this->dbSimple)
$this->dbSimple->setCachePrefix($prx);
return $old;
}

Expand Down
47 changes: 23 additions & 24 deletions src/DbSimple/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,29 @@
*/
abstract class Database extends LastError
{
// Identifiers prefix (used for ?_ placeholder).
private $_identPrefix = '';

// Queries statistics.
private $_statistics = array(
'time' => 0,
'count' => 0,
);

private $_cachePrefix = '';
private $_className = '';

private $_logger = null;
private $_cacher = null;
private $_placeholderArgs, $_placeholderNativeArgs, $_placeholderCache=array();
private $_placeholderNoValueFound;

/**
* When string representation of row (in characters) is greater than this,
* row data will not be logged.
*/
private $MAX_LOG_ROW_LEN = 128;

/**
* Public methods.
*/
Expand Down Expand Up @@ -1148,30 +1171,6 @@ private function _logQueryStat($queryTime, $fetchTime, $firstFetchTime, $rows)

$this->_logQuery($log, true);
}


// Identifiers prefix (used for ?_ placeholder).
private $_identPrefix = '';

// Queries statistics.
private $_statistics = array(
'time' => 0,
'count' => 0,
);

private $_cachePrefix = '';
private $_className = '';

private $_logger = null;
private $_cacher = null;
private $_placeholderArgs, $_placeholderNativeArgs, $_placeholderCache=array();
private $_placeholderNoValueFound;

/**
* When string representation of row (in characters) is greater than this,
* row data will not be logged.
*/
private $MAX_LOG_ROW_LEN = 128;
}


Expand Down
20 changes: 6 additions & 14 deletions src/DbSimple/Generic.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,23 +72,17 @@ class Generic
* Choose database driver according to DSN. Return new instance
* of this driver.
*/
function connect($dsn)
public static function connect($dsn)
{
// Load database driver and create its instance.
$parsed = Generic::parseDSN($dsn);
$parsed = self::parseDSN($dsn);
if (!$parsed) {
$dummy = null;
return $dummy;
}
$class = 'DbSimple_'.ucfirst($parsed['scheme']);
$class = ucfirst($parsed['scheme']);
if (!class_exists($class)) {
$file = dirname(__FILE__).'/'.ucfirst($parsed['scheme']). ".php";
if (is_file($file)) {
require_once($file);
} else {
trigger_error("Error loading database driver: no file $file", E_USER_ERROR);
return null;
}
throw new \LogicException("Error loading database driver: no class $class");
}
$object = new $class($parsed);
if (isset($parsed['ident_prefix'])) {
Expand All @@ -104,7 +98,7 @@ function connect($dsn)
* Parse a data source name.
* See parse_url() for details.
*/
function parseDSN($dsn)
public static function parseDSN($dsn)
{
if (is_array($dsn)) return $dsn;
$parsed = parse_url($dsn);
Expand All @@ -117,6 +111,4 @@ function parseDSN($dsn)
$parsed['dsn'] = $dsn;
return $parsed;
}
}

?>
}
11 changes: 5 additions & 6 deletions src/DbSimple/iffyAdapters/Mypdo.php → src/DbSimple/Mypdo.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@
*
* @version 2.x $Id$
*/
require_once dirname(__FILE__) . '/Database.php';

namespace DbSimple;

/**
* Database class for MySQL.
*/
class DbSimple_Mypdo extends Database
class MyPdo extends Database
{
private $link;

public function DbSimple_Mypdo($dsn)
public function __construct($dsn)
{
$base = preg_replace('{^/}s', '', $dsn['path']);
if (!class_exists('PDO'))
Expand Down Expand Up @@ -139,6 +140,4 @@ protected function _performFetch($result)
return $result;
}

}

?>
}
Loading

0 comments on commit a78803c

Please sign in to comment.