import v1.1.0_beta1 | 2009-08-21
This commit is contained in:
@ -17,15 +17,10 @@
|
||||
* @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: Mysqli.php 12330 2008-11-06 17:03:39Z till $
|
||||
* @version $Id: Mysqli.php 15599 2009-05-16 01:30:48Z yoshida@zend.co.jp $
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Loader
|
||||
*/
|
||||
require_once 'Zend/Loader.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Db_Adapter_Abstract
|
||||
*/
|
||||
@ -234,6 +229,10 @@ class Zend_Db_Adapter_Mysqli extends Zend_Db_Adapter_Abstract
|
||||
$row['Type'] = 'decimal';
|
||||
$row['Precision'] = $matches[1];
|
||||
$row['Scale'] = $matches[2];
|
||||
} else if (preg_match('/^float\((\d+),(\d+)\)/', $row['Type'], $matches)) {
|
||||
$row['Type'] = 'float';
|
||||
$row['Precision'] = $matches[1];
|
||||
$row['Scale'] = $matches[2];
|
||||
} else if (preg_match('/^((?:big|medium|small|tiny)?int)\((\d+)\)/', $row['Type'], $matches)) {
|
||||
$row['Type'] = $matches[1];
|
||||
/**
|
||||
@ -298,22 +297,55 @@ class Zend_Db_Adapter_Mysqli extends Zend_Db_Adapter_Abstract
|
||||
$port = null;
|
||||
}
|
||||
|
||||
$this->_connection = mysqli_init();
|
||||
|
||||
if(!empty($this->_config['driver_options'])) {
|
||||
foreach($this->_config['driver_options'] as $option=>$value) {
|
||||
if(is_string($option)) {
|
||||
// Suppress warnings here
|
||||
// Ignore it if it's not a valid constant
|
||||
$option = @constant(strtoupper($option));
|
||||
if($option === null)
|
||||
continue;
|
||||
}
|
||||
mysqli_options($this->_connection, $option, $value);
|
||||
}
|
||||
}
|
||||
|
||||
// Suppress connection warnings here.
|
||||
// Throw an exception instead.
|
||||
@$this->_connection = new mysqli(
|
||||
$_isConnected = @mysqli_real_connect(
|
||||
$this->_connection,
|
||||
$this->_config['host'],
|
||||
$this->_config['username'],
|
||||
$this->_config['password'],
|
||||
$this->_config['dbname'],
|
||||
$port
|
||||
);
|
||||
if ($this->_connection === false || mysqli_connect_errno()) {
|
||||
|
||||
if ($_isConnected === false || mysqli_connect_errno()) {
|
||||
|
||||
$this->closeConnection();
|
||||
/**
|
||||
* @see Zend_Db_Adapter_Mysqli_Exception
|
||||
*/
|
||||
require_once 'Zend/Db/Adapter/Mysqli/Exception.php';
|
||||
throw new Zend_Db_Adapter_Mysqli_Exception(mysqli_connect_error());
|
||||
}
|
||||
|
||||
if (!empty($this->_config['charset'])) {
|
||||
mysqli_set_charset($this->_connection, $this->_config['charset']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a connection is active
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isConnected()
|
||||
{
|
||||
return ((bool) ($this->_connection instanceof mysqli));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -323,7 +355,9 @@ class Zend_Db_Adapter_Mysqli extends Zend_Db_Adapter_Abstract
|
||||
*/
|
||||
public function closeConnection()
|
||||
{
|
||||
$this->_connection->close();
|
||||
if ($this->isConnected()) {
|
||||
$this->_connection->close();
|
||||
}
|
||||
$this->_connection = null;
|
||||
}
|
||||
|
||||
@ -340,7 +374,10 @@ class Zend_Db_Adapter_Mysqli extends Zend_Db_Adapter_Abstract
|
||||
$this->_stmt->close();
|
||||
}
|
||||
$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);
|
||||
if ($stmt === false) {
|
||||
return false;
|
||||
@ -495,4 +532,18 @@ class Zend_Db_Adapter_Mysqli extends Zend_Db_Adapter_Abstract
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve server version in PHP style
|
||||
*
|
||||
*@return string
|
||||
*/
|
||||
public function getServerVersion()
|
||||
{
|
||||
$this->_connect();
|
||||
$version = $this->_connection->server_version;
|
||||
$major = (int) ($version / 10000);
|
||||
$minor = (int) ($version % 10000 / 100);
|
||||
$revision = (int) ($version % 100);
|
||||
return $major . '.' . $minor . '.' . $revision;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user