import v1.1.0_beta1 | 2009-08-21
This commit is contained in:
@ -17,7 +17,7 @@
|
||||
* @subpackage Adapter
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Abstract.php 12629 2008-11-13 17:23:13Z alexander $
|
||||
* @version $Id: Abstract.php 15577 2009-05-14 12:43:34Z matthew $
|
||||
*/
|
||||
|
||||
|
||||
@ -27,12 +27,6 @@
|
||||
require_once 'Zend/Db/Adapter/Abstract.php';
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Loader
|
||||
*/
|
||||
require_once 'Zend/Loader.php';
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Db_Statement_Pdo
|
||||
*/
|
||||
@ -72,6 +66,7 @@ abstract class Zend_Db_Adapter_Pdo_Abstract extends Zend_Db_Adapter_Abstract
|
||||
unset($dsn['username']);
|
||||
unset($dsn['password']);
|
||||
unset($dsn['options']);
|
||||
unset($dsn['charset']);
|
||||
unset($dsn['driver_options']);
|
||||
|
||||
// use all remaining parts in the DSN
|
||||
@ -145,6 +140,16 @@ abstract class Zend_Db_Adapter_Pdo_Abstract extends Zend_Db_Adapter_Abstract
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a connection is active
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isConnected()
|
||||
{
|
||||
return ((bool) ($this->_connection instanceof PDO));
|
||||
}
|
||||
|
||||
/**
|
||||
* Force the connection to close.
|
||||
*
|
||||
@ -166,7 +171,10 @@ abstract class Zend_Db_Adapter_Pdo_Abstract extends Zend_Db_Adapter_Abstract
|
||||
{
|
||||
$this->_connect();
|
||||
$stmtClass = $this->_defaultStmtClass;
|
||||
Zend_Loader::loadClass($stmtClass);
|
||||
if (!class_exists($stmtClass)) {
|
||||
require_once 'Zend/Loader.php';
|
||||
Zend_Loader::loadClass($stmtClass);
|
||||
}
|
||||
$stmt = new $stmtClass($this, $sql);
|
||||
$stmt->setFetchMode($this->_fetchMode);
|
||||
return $stmt;
|
||||
@ -206,6 +214,10 @@ abstract class Zend_Db_Adapter_Pdo_Abstract extends Zend_Db_Adapter_Abstract
|
||||
*/
|
||||
public function query($sql, $bind = array())
|
||||
{
|
||||
if (empty($bind) && $sql instanceof Zend_Db_Select) {
|
||||
$bind = $sql->getBind();
|
||||
}
|
||||
|
||||
if (is_array($bind)) {
|
||||
foreach ($bind as $name => $value) {
|
||||
if (!is_int($name) && !preg_match('/^:/', $name)) {
|
||||
@ -227,6 +239,42 @@ abstract class Zend_Db_Adapter_Pdo_Abstract extends Zend_Db_Adapter_Abstract
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes an SQL statement and return the number of affected rows
|
||||
*
|
||||
* @param mixed $sql The SQL statement with placeholders.
|
||||
* May be a string or Zend_Db_Select.
|
||||
* @return integer Number of rows that were modified
|
||||
* or deleted by the SQL statement
|
||||
*/
|
||||
public function exec($sql)
|
||||
{
|
||||
if ($sql instanceof Zend_Db_Select) {
|
||||
$sql = $sql->assemble();
|
||||
}
|
||||
|
||||
try {
|
||||
$affected = $this->getConnection()->exec($sql);
|
||||
|
||||
if ($affected === false) {
|
||||
$errorInfo = $this->getConnection()->errorInfo();
|
||||
/**
|
||||
* @see Zend_Db_Adapter_Exception
|
||||
*/
|
||||
require_once 'Zend/Db/Adapter/Exception.php';
|
||||
throw new Zend_Db_Adapter_Exception($errorInfo[2]);
|
||||
}
|
||||
|
||||
return $affected;
|
||||
} catch (PDOException $e) {
|
||||
/**
|
||||
* @see Zend_Db_Adapter_Exception
|
||||
*/
|
||||
require_once 'Zend/Db/Adapter/Exception.php';
|
||||
throw new Zend_Db_Adapter_Exception($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Quote a raw string.
|
||||
*
|
||||
@ -322,5 +370,26 @@ abstract class Zend_Db_Adapter_Pdo_Abstract extends Zend_Db_Adapter_Abstract
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve server version in PHP style
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getServerVersion()
|
||||
{
|
||||
$this->_connect();
|
||||
try {
|
||||
$version = $this->_connection->getAttribute(PDO::ATTR_SERVER_VERSION);
|
||||
} catch (PDOException $e) {
|
||||
// In case of the driver doesn't support getting attributes
|
||||
return null;
|
||||
}
|
||||
$matches = null;
|
||||
if (preg_match('/((?:[0-9]{1,2}\.){1,3}[0-9]{1,2})/', $version, $matches)) {
|
||||
return $matches[1];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user