CC-2166: Packaging Improvements. Moved the Zend app into airtime_mvc. It is now installed to /var/www/airtime. Storage is now set to /srv/airtime/stor. Utils are now installed to /usr/lib/airtime/utils/. Added install/airtime-dircheck.php as a simple test to see if everything is install/uninstalled correctly.

This commit is contained in:
Paul Baranowski 2011-04-14 18:55:04 -04:00
parent 514777e8d2
commit b11cbd8159
4546 changed files with 138 additions and 51 deletions

View file

@ -0,0 +1,360 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Db
* @subpackage Statement
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Db2.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* @see Zend_Db_Statement
*/
require_once 'Zend/Db/Statement.php';
/**
* Extends for DB2 native adapter.
*
* @package Zend_Db
* @subpackage Statement
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Db_Statement_Db2 extends Zend_Db_Statement
{
/**
* Column names.
*/
protected $_keys;
/**
* Fetched result values.
*/
protected $_values;
/**
* Prepare a statement handle.
*
* @param string $sql
* @return void
* @throws Zend_Db_Statement_Db2_Exception
*/
public function _prepare($sql)
{
$connection = $this->_adapter->getConnection();
// db2_prepare on i5 emits errors, these need to be
// suppressed so that proper exceptions can be thrown
$this->_stmt = @db2_prepare($connection, $sql);
if (!$this->_stmt) {
/**
* @see Zend_Db_Statement_Db2_Exception
*/
require_once 'Zend/Db/Statement/Db2/Exception.php';
throw new Zend_Db_Statement_Db2_Exception(
db2_stmt_errormsg(),
db2_stmt_error()
);
}
}
/**
* Binds a parameter to the specified variable name.
*
* @param mixed $parameter Name the parameter, either integer or string.
* @param mixed $variable Reference to PHP variable containing the value.
* @param mixed $type OPTIONAL Datatype of SQL parameter.
* @param mixed $length OPTIONAL Length of SQL parameter.
* @param mixed $options OPTIONAL Other options.
* @return bool
* @throws Zend_Db_Statement_Db2_Exception
*/
public function _bindParam($parameter, &$variable, $type = null, $length = null, $options = null)
{
if ($type === null) {
$type = DB2_PARAM_IN;
}
if (isset($options['data-type'])) {
$datatype = $options['data-type'];
} else {
$datatype = DB2_CHAR;
}
if (!db2_bind_param($this->_stmt, $position, "variable", $type, $datatype)) {
/**
* @see Zend_Db_Statement_Db2_Exception
*/
require_once 'Zend/Db/Statement/Db2/Exception.php';
throw new Zend_Db_Statement_Db2_Exception(
db2_stmt_errormsg(),
db2_stmt_error()
);
}
return true;
}
/**
* Closes the cursor, allowing the statement to be executed again.
*
* @return bool
*/
public function closeCursor()
{
if (!$this->_stmt) {
return false;
}
db2_free_stmt($this->_stmt);
$this->_stmt = false;
return true;
}
/**
* Returns the number of columns in the result set.
* Returns null if the statement has no result set metadata.
*
* @return int The number of columns.
*/
public function columnCount()
{
if (!$this->_stmt) {
return false;
}
return db2_num_fields($this->_stmt);
}
/**
* Retrieves the error code, if any, associated with the last operation on
* the statement handle.
*
* @return string error code.
*/
public function errorCode()
{
if (!$this->_stmt) {
return false;
}
$error = db2_stmt_error();
if ($error === '') {
return false;
}
return $error;
}
/**
* Retrieves an array of error information, if any, associated with the
* last operation on the statement handle.
*
* @return array
*/
public function errorInfo()
{
$error = $this->errorCode();
if ($error === false){
return false;
}
/*
* Return three-valued array like PDO. But DB2 does not distinguish
* between SQLCODE and native RDBMS error code, so repeat the SQLCODE.
*/
return array(
$error,
$error,
db2_stmt_errormsg()
);
}
/**
* Executes a prepared statement.
*
* @param array $params OPTIONAL Values to bind to parameter placeholders.
* @return bool
* @throws Zend_Db_Statement_Db2_Exception
*/
public function _execute(array $params = null)
{
if (!$this->_stmt) {
return false;
}
$retval = true;
if ($params !== null) {
$retval = @db2_execute($this->_stmt, $params);
} else {
$retval = @db2_execute($this->_stmt);
}
if ($retval === false) {
/**
* @see Zend_Db_Statement_Db2_Exception
*/
require_once 'Zend/Db/Statement/Db2/Exception.php';
throw new Zend_Db_Statement_Db2_Exception(
db2_stmt_errormsg(),
db2_stmt_error());
}
$this->_keys = array();
if ($field_num = $this->columnCount()) {
for ($i = 0; $i < $field_num; $i++) {
$name = db2_field_name($this->_stmt, $i);
$this->_keys[] = $name;
}
}
$this->_values = array();
if ($this->_keys) {
$this->_values = array_fill(0, count($this->_keys), null);
}
return $retval;
}
/**
* Fetches a row from the result set.
*
* @param int $style OPTIONAL Fetch mode for this fetch operation.
* @param int $cursor OPTIONAL Absolute, relative, or other.
* @param int $offset OPTIONAL Number for absolute or relative cursors.
* @return mixed Array, object, or scalar depending on fetch mode.
* @throws Zend_Db_Statement_Db2_Exception
*/
public function fetch($style = null, $cursor = null, $offset = null)
{
if (!$this->_stmt) {
return false;
}
if ($style === null) {
$style = $this->_fetchMode;
}
switch ($style) {
case Zend_Db::FETCH_NUM :
$row = db2_fetch_array($this->_stmt);
break;
case Zend_Db::FETCH_ASSOC :
$row = db2_fetch_assoc($this->_stmt);
break;
case Zend_Db::FETCH_BOTH :
$row = db2_fetch_both($this->_stmt);
break;
case Zend_Db::FETCH_OBJ :
$row = db2_fetch_object($this->_stmt);
break;
case Zend_Db::FETCH_BOUND:
$row = db2_fetch_both($this->_stmt);
if ($row !== false) {
return $this->_fetchBound($row);
}
break;
default:
/**
* @see Zend_Db_Statement_Db2_Exception
*/
require_once 'Zend/Db/Statement/Db2/Exception.php';
throw new Zend_Db_Statement_Db2_Exception("Invalid fetch mode '$style' specified");
break;
}
return $row;
}
/**
* Fetches the next row and returns it as an object.
*
* @param string $class OPTIONAL Name of the class to create.
* @param array $config OPTIONAL Constructor arguments for the class.
* @return mixed One object instance of the specified class.
*/
public function fetchObject($class = 'stdClass', array $config = array())
{
$obj = $this->fetch(Zend_Db::FETCH_OBJ);
return $obj;
}
/**
* Retrieves the next rowset (result set) for a SQL statement that has
* multiple result sets. An example is a stored procedure that returns
* the results of multiple queries.
*
* @return bool
* @throws Zend_Db_Statement_Db2_Exception
*/
public function nextRowset()
{
/**
* @see Zend_Db_Statement_Db2_Exception
*/
require_once 'Zend/Db/Statement/Db2/Exception.php';
throw new Zend_Db_Statement_Db2_Exception(__FUNCTION__ . '() is not implemented');
}
/**
* Returns the number of rows affected by the execution of the
* last INSERT, DELETE, or UPDATE statement executed by this
* statement object.
*
* @return int The number of rows affected.
*/
public function rowCount()
{
if (!$this->_stmt) {
return false;
}
$num = @db2_num_rows($this->_stmt);
if ($num === false) {
return 0;
}
return $num;
}
/**
* Returns an array containing all of the result set rows.
*
* @param int $style OPTIONAL Fetch mode.
* @param int $col OPTIONAL Column number, if fetch mode is by column.
* @return array Collection of rows, each in a format by the fetch mode.
*
* Behaves like parent, but if limit()
* is used, the final result removes the extra column
* 'zend_db_rownum'
*/
public function fetchAll($style = null, $col = null)
{
$data = parent::fetchAll($style, $col);
$results = array();
$remove = $this->_adapter->foldCase('ZEND_DB_ROWNUM');
foreach ($data as $row) {
if (is_array($row) && array_key_exists($remove, $row)) {
unset($row[$remove]);
}
$results[] = $row;
}
return $results;
}
}

View file

@ -0,0 +1,58 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Db
* @subpackage Statement
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* Zend_Db_Statement_Exception
*/
require_once 'Zend/Db/Statement/Exception.php';
/**
* @package Zend_Db
* @subpackage Statement
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Db_Statement_Db2_Exception extends Zend_Db_Statement_Exception
{
/**
* @var string
*/
protected $code = '00000';
/**
* @var string
*/
protected $message = 'unknown exception';
/**
* @param string $msg
* @param string $state
*/
function __construct($msg = 'unknown exception', $state = '00000')
{
$this->message = $msg;
$this->code = $state;
}
}

View file

@ -0,0 +1,56 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Db
* @subpackage Statement
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Exception.php 20514 2010-01-22 07:57:10Z ralph $
*/
/**
* @see Zend_Db_Exception
*/
require_once 'Zend/Db/Exception.php';
/**
* Zend_Db_Statement_Exception
*
* @category Zend
* @package Zend_Db
* @subpackage Statement
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Db_Statement_Exception extends Zend_Db_Exception
{
/**
* Check if this general exception has a specific database driver specific exception nested inside.
*
* @return bool
*/
public function hasChainedException()
{
return ($this->getPrevious() !== null);
}
/**
* @return Exception|null
*/
public function getChainedException()
{
return $this->getPrevious();
}
}

View file

@ -0,0 +1,203 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Db
* @subpackage Statement
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Interface.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* Emulates a PDOStatement for native database adapters.
*
* @category Zend
* @package Zend_Db
* @subpackage Statement
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface Zend_Db_Statement_Interface
{
/**
* Bind a column of the statement result set to a PHP variable.
*
* @param string $column Name the column in the result set, either by
* position or by name.
* @param mixed $param Reference to the PHP variable containing the value.
* @param mixed $type OPTIONAL
* @return bool
* @throws Zend_Db_Statement_Exception
*/
public function bindColumn($column, &$param, $type = null);
/**
* Binds a parameter to the specified variable name.
*
* @param mixed $parameter Name the parameter, either integer or string.
* @param mixed $variable Reference to PHP variable containing the value.
* @param mixed $type OPTIONAL Datatype of SQL parameter.
* @param mixed $length OPTIONAL Length of SQL parameter.
* @param mixed $options OPTIONAL Other options.
* @return bool
* @throws Zend_Db_Statement_Exception
*/
public function bindParam($parameter, &$variable, $type = null, $length = null, $options = null);
/**
* Binds a value to a parameter.
*
* @param mixed $parameter Name the parameter, either integer or string.
* @param mixed $value Scalar value to bind to the parameter.
* @param mixed $type OPTIONAL Datatype of the parameter.
* @return bool
* @throws Zend_Db_Statement_Exception
*/
public function bindValue($parameter, $value, $type = null);
/**
* Closes the cursor, allowing the statement to be executed again.
*
* @return bool
* @throws Zend_Db_Statement_Exception
*/
public function closeCursor();
/**
* Returns the number of columns in the result set.
* Returns null if the statement has no result set metadata.
*
* @return int The number of columns.
* @throws Zend_Db_Statement_Exception
*/
public function columnCount();
/**
* Retrieves the error code, if any, associated with the last operation on
* the statement handle.
*
* @return string error code.
* @throws Zend_Db_Statement_Exception
*/
public function errorCode();
/**
* Retrieves an array of error information, if any, associated with the
* last operation on the statement handle.
*
* @return array
* @throws Zend_Db_Statement_Exception
*/
public function errorInfo();
/**
* Executes a prepared statement.
*
* @param array $params OPTIONAL Values to bind to parameter placeholders.
* @return bool
* @throws Zend_Db_Statement_Exception
*/
public function execute(array $params = array());
/**
* Fetches a row from the result set.
*
* @param int $style OPTIONAL Fetch mode for this fetch operation.
* @param int $cursor OPTIONAL Absolute, relative, or other.
* @param int $offset OPTIONAL Number for absolute or relative cursors.
* @return mixed Array, object, or scalar depending on fetch mode.
* @throws Zend_Db_Statement_Exception
*/
public function fetch($style = null, $cursor = null, $offset = null);
/**
* Returns an array containing all of the result set rows.
*
* @param int $style OPTIONAL Fetch mode.
* @param int $col OPTIONAL Column number, if fetch mode is by column.
* @return array Collection of rows, each in a format by the fetch mode.
* @throws Zend_Db_Statement_Exception
*/
public function fetchAll($style = null, $col = null);
/**
* Returns a single column from the next row of a result set.
*
* @param int $col OPTIONAL Position of the column to fetch.
* @return string
* @throws Zend_Db_Statement_Exception
*/
public function fetchColumn($col = 0);
/**
* Fetches the next row and returns it as an object.
*
* @param string $class OPTIONAL Name of the class to create.
* @param array $config OPTIONAL Constructor arguments for the class.
* @return mixed One object instance of the specified class.
* @throws Zend_Db_Statement_Exception
*/
public function fetchObject($class = 'stdClass', array $config = array());
/**
* Retrieve a statement attribute.
*
* @param string $key Attribute name.
* @return mixed Attribute value.
* @throws Zend_Db_Statement_Exception
*/
public function getAttribute($key);
/**
* Retrieves the next rowset (result set) for a SQL statement that has
* multiple result sets. An example is a stored procedure that returns
* the results of multiple queries.
*
* @return bool
* @throws Zend_Db_Statement_Exception
*/
public function nextRowset();
/**
* Returns the number of rows affected by the execution of the
* last INSERT, DELETE, or UPDATE statement executed by this
* statement object.
*
* @return int The number of rows affected.
* @throws Zend_Db_Statement_Exception
*/
public function rowCount();
/**
* Set a statement attribute.
*
* @param string $key Attribute name.
* @param mixed $val Attribute value.
* @return bool
* @throws Zend_Db_Statement_Exception
*/
public function setAttribute($key, $val);
/**
* Set the default fetch mode for this statement.
*
* @param int $mode The fetch mode.
* @return bool
* @throws Zend_Db_Statement_Exception
*/
public function setFetchMode($mode);
}

View file

@ -0,0 +1,362 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Db
* @subpackage Statement
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Mysqli.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* @see Zend_Db_Statement
*/
require_once 'Zend/Db/Statement.php';
/**
* Extends for Mysqli
*
* @category Zend
* @package Zend_Db
* @subpackage Statement
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Db_Statement_Mysqli extends Zend_Db_Statement
{
/**
* Column names.
*
* @var array
*/
protected $_keys;
/**
* Fetched result values.
*
* @var array
*/
protected $_values;
/**
* @var array
*/
protected $_meta = null;
/**
* @param string $sql
* @return void
* @throws Zend_Db_Statement_Mysqli_Exception
*/
public function _prepare($sql)
{
$mysqli = $this->_adapter->getConnection();
$this->_stmt = $mysqli->prepare($sql);
if ($this->_stmt === false || $mysqli->errno) {
/**
* @see Zend_Db_Statement_Mysqli_Exception
*/
require_once 'Zend/Db/Statement/Mysqli/Exception.php';
throw new Zend_Db_Statement_Mysqli_Exception("Mysqli prepare error: " . $mysqli->error, $mysqli->errno);
}
}
/**
* Binds a parameter to the specified variable name.
*
* @param mixed $parameter Name the parameter, either integer or string.
* @param mixed $variable Reference to PHP variable containing the value.
* @param mixed $type OPTIONAL Datatype of SQL parameter.
* @param mixed $length OPTIONAL Length of SQL parameter.
* @param mixed $options OPTIONAL Other options.
* @return bool
* @throws Zend_Db_Statement_Mysqli_Exception
*/
protected function _bindParam($parameter, &$variable, $type = null, $length = null, $options = null)
{
return true;
}
/**
* Closes the cursor and the statement.
*
* @return bool
*/
public function close()
{
if ($this->_stmt) {
$r = $this->_stmt->close();
$this->_stmt = null;
return $r;
}
return false;
}
/**
* Closes the cursor, allowing the statement to be executed again.
*
* @return bool
*/
public function closeCursor()
{
if ($stmt = $this->_stmt) {
$mysqli = $this->_adapter->getConnection();
while ($mysqli->more_results()) {
$mysqli->next_result();
}
$this->_stmt->free_result();
return $this->_stmt->reset();
}
return false;
}
/**
* Returns the number of columns in the result set.
* Returns null if the statement has no result set metadata.
*
* @return int The number of columns.
*/
public function columnCount()
{
if (isset($this->_meta) && $this->_meta) {
return $this->_meta->field_count;
}
return 0;
}
/**
* Retrieves the error code, if any, associated with the last operation on
* the statement handle.
*
* @return string error code.
*/
public function errorCode()
{
if (!$this->_stmt) {
return false;
}
return substr($this->_stmt->sqlstate, 0, 5);
}
/**
* Retrieves an array of error information, if any, associated with the
* last operation on the statement handle.
*
* @return array
*/
public function errorInfo()
{
if (!$this->_stmt) {
return false;
}
return array(
substr($this->_stmt->sqlstate, 0, 5),
$this->_stmt->errno,
$this->_stmt->error,
);
}
/**
* Executes a prepared statement.
*
* @param array $params OPTIONAL Values to bind to parameter placeholders.
* @return bool
* @throws Zend_Db_Statement_Mysqli_Exception
*/
public function _execute(array $params = null)
{
if (!$this->_stmt) {
return false;
}
// if no params were given as an argument to execute(),
// then default to the _bindParam array
if ($params === null) {
$params = $this->_bindParam;
}
// send $params as input parameters to the statement
if ($params) {
array_unshift($params, str_repeat('s', count($params)));
$stmtParams = array();
foreach ($params as $k => &$value) {
$stmtParams[$k] = &$value;
}
call_user_func_array(
array($this->_stmt, 'bind_param'),
$stmtParams
);
}
// execute the statement
$retval = $this->_stmt->execute();
if ($retval === false) {
/**
* @see Zend_Db_Statement_Mysqli_Exception
*/
require_once 'Zend/Db/Statement/Mysqli/Exception.php';
throw new Zend_Db_Statement_Mysqli_Exception("Mysqli statement execute error : " . $this->_stmt->error, $this->_stmt->errno);
}
// retain metadata
if ($this->_meta === null) {
$this->_meta = $this->_stmt->result_metadata();
if ($this->_stmt->errno) {
/**
* @see Zend_Db_Statement_Mysqli_Exception
*/
require_once 'Zend/Db/Statement/Mysqli/Exception.php';
throw new Zend_Db_Statement_Mysqli_Exception("Mysqli statement metadata error: " . $this->_stmt->error, $this->_stmt->errno);
}
}
// statements that have no result set do not return metadata
if ($this->_meta !== false) {
// get the column names that will result
$this->_keys = array();
foreach ($this->_meta->fetch_fields() as $col) {
$this->_keys[] = $this->_adapter->foldCase($col->name);
}
// set up a binding space for result variables
$this->_values = array_fill(0, count($this->_keys), null);
// set up references to the result binding space.
// just passing $this->_values in the call_user_func_array()
// below won't work, you need references.
$refs = array();
foreach ($this->_values as $i => &$f) {
$refs[$i] = &$f;
}
$this->_stmt->store_result();
// bind to the result variables
call_user_func_array(
array($this->_stmt, 'bind_result'),
$this->_values
);
}
return $retval;
}
/**
* Fetches a row from the result set.
*
* @param int $style OPTIONAL Fetch mode for this fetch operation.
* @param int $cursor OPTIONAL Absolute, relative, or other.
* @param int $offset OPTIONAL Number for absolute or relative cursors.
* @return mixed Array, object, or scalar depending on fetch mode.
* @throws Zend_Db_Statement_Mysqli_Exception
*/
public function fetch($style = null, $cursor = null, $offset = null)
{
if (!$this->_stmt) {
return false;
}
// fetch the next result
$retval = $this->_stmt->fetch();
switch ($retval) {
case null: // end of data
case false: // error occurred
$this->_stmt->reset();
return false;
default:
// fallthrough
}
// make sure we have a fetch mode
if ($style === null) {
$style = $this->_fetchMode;
}
// dereference the result values, otherwise things like fetchAll()
// return the same values for every entry (because of the reference).
$values = array();
foreach ($this->_values as $key => $val) {
$values[] = $val;
}
$row = false;
switch ($style) {
case Zend_Db::FETCH_NUM:
$row = $values;
break;
case Zend_Db::FETCH_ASSOC:
$row = array_combine($this->_keys, $values);
break;
case Zend_Db::FETCH_BOTH:
$assoc = array_combine($this->_keys, $values);
$row = array_merge($values, $assoc);
break;
case Zend_Db::FETCH_OBJ:
$row = (object) array_combine($this->_keys, $values);
break;
case Zend_Db::FETCH_BOUND:
$assoc = array_combine($this->_keys, $values);
$row = array_merge($values, $assoc);
return $this->_fetchBound($row);
break;
default:
/**
* @see Zend_Db_Statement_Mysqli_Exception
*/
require_once 'Zend/Db/Statement/Mysqli/Exception.php';
throw new Zend_Db_Statement_Mysqli_Exception("Invalid fetch mode '$style' specified");
break;
}
return $row;
}
/**
* Retrieves the next rowset (result set) for a SQL statement that has
* multiple result sets. An example is a stored procedure that returns
* the results of multiple queries.
*
* @return bool
* @throws Zend_Db_Statement_Mysqli_Exception
*/
public function nextRowset()
{
/**
* @see Zend_Db_Statement_Mysqli_Exception
*/
require_once 'Zend/Db/Statement/Mysqli/Exception.php';
throw new Zend_Db_Statement_Mysqli_Exception(__FUNCTION__.'() is not implemented');
}
/**
* Returns the number of rows affected by the execution of the
* last INSERT, DELETE, or UPDATE statement executed by this
* statement object.
*
* @return int The number of rows affected.
*/
public function rowCount()
{
if (!$this->_adapter) {
return false;
}
$mysqli = $this->_adapter->getConnection();
return $mysqli->affected_rows;
}
}

View file

@ -0,0 +1,38 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Db
* @subpackage Statement
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* Zend_Db_Statement_Exception
*/
require_once 'Zend/Db/Statement/Exception.php';
/**
* @package Zend_Db
* @subpackage Statement
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Db_Statement_Mysqli_Exception extends Zend_Db_Statement_Exception
{
}

View file

@ -0,0 +1,577 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Db
* @subpackage Statement
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Oracle.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* @see Zend_Db_Statement
*/
require_once 'Zend/Db/Statement.php';
/**
* Extends for Oracle.
*
* @category Zend
* @package Zend_Db
* @subpackage Statement
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Db_Statement_Oracle extends Zend_Db_Statement
{
/**
* Column names.
*/
protected $_keys;
/**
* Fetched result values.
*/
protected $_values;
/**
* Check if LOB field are returned as string
* instead of OCI-Lob object
*
* @var boolean
*/
protected $_lobAsString = false;
/**
* Activate/deactivate return of LOB as string
*
* @param string $lob_as_string
* @return Zend_Db_Statement_Oracle
*/
public function setLobAsString($lob_as_string)
{
$this->_lobAsString = (bool) $lob_as_string;
return $this;
}
/**
* Return whether or not LOB are returned as string
*
* @return boolean
*/
public function getLobAsString()
{
return $this->_lobAsString;
}
/**
* Prepares statement handle
*
* @param string $sql
* @return void
* @throws Zend_Db_Statement_Oracle_Exception
*/
protected function _prepare($sql)
{
$connection = $this->_adapter->getConnection();
$this->_stmt = oci_parse($connection, $sql);
if (!$this->_stmt) {
/**
* @see Zend_Db_Statement_Oracle_Exception
*/
require_once 'Zend/Db/Statement/Oracle/Exception.php';
throw new Zend_Db_Statement_Oracle_Exception(oci_error($connection));
}
}
/**
* Binds a parameter to the specified variable name.
*
* @param mixed $parameter Name the parameter, either integer or string.
* @param mixed $variable Reference to PHP variable containing the value.
* @param mixed $type OPTIONAL Datatype of SQL parameter.
* @param mixed $length OPTIONAL Length of SQL parameter.
* @param mixed $options OPTIONAL Other options.
* @return bool
* @throws Zend_Db_Statement_Exception
*/
protected function _bindParam($parameter, &$variable, $type = null, $length = null, $options = null)
{
// default value
if ($type === NULL) {
$type = SQLT_CHR;
}
// default value
if ($length === NULL) {
$length = -1;
}
$retval = @oci_bind_by_name($this->_stmt, $parameter, $variable, $length, $type);
if ($retval === false) {
/**
* @see Zend_Db_Adapter_Oracle_Exception
*/
require_once 'Zend/Db/Statement/Oracle/Exception.php';
throw new Zend_Db_Statement_Oracle_Exception(oci_error($this->_stmt));
}
return true;
}
/**
* Closes the cursor, allowing the statement to be executed again.
*
* @return bool
*/
public function closeCursor()
{
if (!$this->_stmt) {
return false;
}
oci_free_statement($this->_stmt);
$this->_stmt = false;
return true;
}
/**
* Returns the number of columns in the result set.
* Returns null if the statement has no result set metadata.
*
* @return int The number of columns.
*/
public function columnCount()
{
if (!$this->_stmt) {
return false;
}
return oci_num_fields($this->_stmt);
}
/**
* Retrieves the error code, if any, associated with the last operation on
* the statement handle.
*
* @return string error code.
*/
public function errorCode()
{
if (!$this->_stmt) {
return false;
}
$error = oci_error($this->_stmt);
if (!$error) {
return false;
}
return $error['code'];
}
/**
* Retrieves an array of error information, if any, associated with the
* last operation on the statement handle.
*
* @return array
*/
public function errorInfo()
{
if (!$this->_stmt) {
return false;
}
$error = oci_error($this->_stmt);
if (!$error) {
return false;
}
if (isset($error['sqltext'])) {
return array(
$error['code'],
$error['message'],
$error['offset'],
$error['sqltext'],
);
} else {
return array(
$error['code'],
$error['message'],
);
}
}
/**
* Executes a prepared statement.
*
* @param array $params OPTIONAL Values to bind to parameter placeholders.
* @return bool
* @throws Zend_Db_Statement_Exception
*/
public function _execute(array $params = null)
{
$connection = $this->_adapter->getConnection();
if (!$this->_stmt) {
return false;
}
if ($params !== null) {
if (!is_array($params)) {
$params = array($params);
}
$error = false;
foreach (array_keys($params) as $name) {
if (!@oci_bind_by_name($this->_stmt, $name, $params[$name], -1)) {
$error = true;
break;
}
}
if ($error) {
/**
* @see Zend_Db_Adapter_Oracle_Exception
*/
require_once 'Zend/Db/Statement/Oracle/Exception.php';
throw new Zend_Db_Statement_Oracle_Exception(oci_error($this->_stmt));
}
}
$retval = @oci_execute($this->_stmt, $this->_adapter->_getExecuteMode());
if ($retval === false) {
/**
* @see Zend_Db_Adapter_Oracle_Exception
*/
require_once 'Zend/Db/Statement/Oracle/Exception.php';
throw new Zend_Db_Statement_Oracle_Exception(oci_error($this->_stmt));
}
$this->_keys = Array();
if ($field_num = oci_num_fields($this->_stmt)) {
for ($i = 1; $i <= $field_num; $i++) {
$name = oci_field_name($this->_stmt, $i);
$this->_keys[] = $name;
}
}
$this->_values = Array();
if ($this->_keys) {
$this->_values = array_fill(0, count($this->_keys), null);
}
return $retval;
}
/**
* Fetches a row from the result set.
*
* @param int $style OPTIONAL Fetch mode for this fetch operation.
* @param int $cursor OPTIONAL Absolute, relative, or other.
* @param int $offset OPTIONAL Number for absolute or relative cursors.
* @return mixed Array, object, or scalar depending on fetch mode.
* @throws Zend_Db_Statement_Exception
*/
public function fetch($style = null, $cursor = null, $offset = null)
{
if (!$this->_stmt) {
return false;
}
if ($style === null) {
$style = $this->_fetchMode;
}
$lob_as_string = $this->getLobAsString() ? OCI_RETURN_LOBS : 0;
switch ($style) {
case Zend_Db::FETCH_NUM:
$row = oci_fetch_array($this->_stmt, OCI_NUM | OCI_RETURN_NULLS | $lob_as_string);
break;
case Zend_Db::FETCH_ASSOC:
$row = oci_fetch_array($this->_stmt, OCI_ASSOC | OCI_RETURN_NULLS | $lob_as_string);
break;
case Zend_Db::FETCH_BOTH:
$row = oci_fetch_array($this->_stmt, OCI_BOTH | OCI_RETURN_NULLS | $lob_as_string);
break;
case Zend_Db::FETCH_OBJ:
$row = oci_fetch_object($this->_stmt);
break;
case Zend_Db::FETCH_BOUND:
$row = oci_fetch_array($this->_stmt, OCI_BOTH | OCI_RETURN_NULLS | $lob_as_string);
if ($row !== false) {
return $this->_fetchBound($row);
}
break;
default:
/**
* @see Zend_Db_Adapter_Oracle_Exception
*/
require_once 'Zend/Db/Statement/Oracle/Exception.php';
throw new Zend_Db_Statement_Oracle_Exception(
array(
'code' => 'HYC00',
'message' => "Invalid fetch mode '$style' specified"
)
);
break;
}
if (! $row && $error = oci_error($this->_stmt)) {
/**
* @see Zend_Db_Adapter_Oracle_Exception
*/
require_once 'Zend/Db/Statement/Oracle/Exception.php';
throw new Zend_Db_Statement_Oracle_Exception($error);
}
if (is_array($row) && array_key_exists('zend_db_rownum', $row)) {
unset($row['zend_db_rownum']);
}
return $row;
}
/**
* Returns an array containing all of the result set rows.
*
* @param int $style OPTIONAL Fetch mode.
* @param int $col OPTIONAL Column number, if fetch mode is by column.
* @return array Collection of rows, each in a format by the fetch mode.
* @throws Zend_Db_Statement_Exception
*/
public function fetchAll($style = null, $col = 0)
{
if (!$this->_stmt) {
return false;
}
// make sure we have a fetch mode
if ($style === null) {
$style = $this->_fetchMode;
}
$flags = OCI_FETCHSTATEMENT_BY_ROW;
switch ($style) {
case Zend_Db::FETCH_BOTH:
/**
* @see Zend_Db_Adapter_Oracle_Exception
*/
require_once 'Zend/Db/Statement/Oracle/Exception.php';
throw new Zend_Db_Statement_Oracle_Exception(
array(
'code' => 'HYC00',
'message' => "OCI8 driver does not support fetchAll(FETCH_BOTH), use fetch() in a loop instead"
)
);
// notreached
$flags |= OCI_NUM;
$flags |= OCI_ASSOC;
break;
case Zend_Db::FETCH_NUM:
$flags |= OCI_NUM;
break;
case Zend_Db::FETCH_ASSOC:
$flags |= OCI_ASSOC;
break;
case Zend_Db::FETCH_OBJ:
break;
case Zend_Db::FETCH_COLUMN:
$flags = $flags &~ OCI_FETCHSTATEMENT_BY_ROW;
$flags |= OCI_FETCHSTATEMENT_BY_COLUMN;
$flags |= OCI_NUM;
break;
default:
/**
* @see Zend_Db_Adapter_Oracle_Exception
*/
require_once 'Zend/Db/Statement/Oracle/Exception.php';
throw new Zend_Db_Statement_Oracle_Exception(
array(
'code' => 'HYC00',
'message' => "Invalid fetch mode '$style' specified"
)
);
break;
}
$result = Array();
if ($flags != OCI_FETCHSTATEMENT_BY_ROW) { /* not Zend_Db::FETCH_OBJ */
if (! ($rows = oci_fetch_all($this->_stmt, $result, 0, -1, $flags) )) {
if ($error = oci_error($this->_stmt)) {
/**
* @see Zend_Db_Adapter_Oracle_Exception
*/
require_once 'Zend/Db/Statement/Oracle/Exception.php';
throw new Zend_Db_Statement_Oracle_Exception($error);
}
if (!$rows) {
return array();
}
}
if ($style == Zend_Db::FETCH_COLUMN) {
$result = $result[$col];
}
foreach ($result as &$row) {
if (is_array($row) && array_key_exists('zend_db_rownum', $row)) {
unset($row['zend_db_rownum']);
}
}
} else {
while (($row = oci_fetch_object($this->_stmt)) !== false) {
$result [] = $row;
}
if ($error = oci_error($this->_stmt)) {
/**
* @see Zend_Db_Adapter_Oracle_Exception
*/
require_once 'Zend/Db/Statement/Oracle/Exception.php';
throw new Zend_Db_Statement_Oracle_Exception($error);
}
}
return $result;
}
/**
* Returns a single column from the next row of a result set.
*
* @param int $col OPTIONAL Position of the column to fetch.
* @return string
* @throws Zend_Db_Statement_Exception
*/
public function fetchColumn($col = 0)
{
if (!$this->_stmt) {
return false;
}
if (!oci_fetch($this->_stmt)) {
// if no error, there is simply no record
if (!$error = oci_error($this->_stmt)) {
return false;
}
/**
* @see Zend_Db_Adapter_Oracle_Exception
*/
require_once 'Zend/Db/Statement/Oracle/Exception.php';
throw new Zend_Db_Statement_Oracle_Exception($error);
}
$data = oci_result($this->_stmt, $col+1); //1-based
if ($data === false) {
/**
* @see Zend_Db_Adapter_Oracle_Exception
*/
require_once 'Zend/Db/Statement/Oracle/Exception.php';
throw new Zend_Db_Statement_Oracle_Exception(oci_error($this->_stmt));
}
if ($this->getLobAsString()) {
// instanceof doesn't allow '-', we must use a temporary string
$type = 'OCI-Lob';
if ($data instanceof $type) {
$data = $data->read($data->size());
}
}
return $data;
}
/**
* Fetches the next row and returns it as an object.
*
* @param string $class OPTIONAL Name of the class to create.
* @param array $config OPTIONAL Constructor arguments for the class.
* @return mixed One object instance of the specified class.
* @throws Zend_Db_Statement_Exception
*/
public function fetchObject($class = 'stdClass', array $config = array())
{
if (!$this->_stmt) {
return false;
}
$obj = oci_fetch_object($this->_stmt);
if ($error = oci_error($this->_stmt)) {
/**
* @see Zend_Db_Adapter_Oracle_Exception
*/
require_once 'Zend/Db/Statement/Oracle/Exception.php';
throw new Zend_Db_Statement_Oracle_Exception($error);
}
/* @todo XXX handle parameters */
return $obj;
}
/**
* Retrieves the next rowset (result set) for a SQL statement that has
* multiple result sets. An example is a stored procedure that returns
* the results of multiple queries.
*
* @return bool
* @throws Zend_Db_Statement_Exception
*/
public function nextRowset()
{
/**
* @see Zend_Db_Statement_Oracle_Exception
*/
require_once 'Zend/Db/Statement/Oracle/Exception.php';
throw new Zend_Db_Statement_Oracle_Exception(
array(
'code' => 'HYC00',
'message' => 'Optional feature not implemented'
)
);
}
/**
* Returns the number of rows affected by the execution of the
* last INSERT, DELETE, or UPDATE statement executed by this
* statement object.
*
* @return int The number of rows affected.
* @throws Zend_Db_Statement_Exception
*/
public function rowCount()
{
if (!$this->_stmt) {
return false;
}
$num_rows = oci_num_rows($this->_stmt);
if ($num_rows === false) {
/**
* @see Zend_Db_Adapter_Oracle_Exception
*/
require_once 'Zend/Db/Statement/Oracle/Exception.php';
throw new Zend_Db_Statement_Oracle_Exception(oci_error($this->_stmt));
}
return $num_rows;
}
}

View file

@ -0,0 +1,59 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Db
* @subpackage Statement
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* Zend_Db_Statement_Exception
*/
require_once 'Zend/Db/Statement/Exception.php';
/**
* @category Zend
* @package Zend_Db
* @subpackage Statement
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Db_Statement_Oracle_Exception extends Zend_Db_Statement_Exception
{
protected $message = 'Unknown exception';
protected $code = 0;
function __construct($error = null, $code = 0)
{
if (is_array($error)) {
if (!isset($error['offset'])) {
$this->message = $error['code']." ".$error['message'];
} else {
$this->message = $error['code']." ".$error['message']." ";
$this->message .= substr($error['sqltext'], 0, $error['offset']);
$this->message .= "*";
$this->message .= substr($error['sqltext'], $error['offset']);
}
$this->code = $error['code'];
}
if (!$this->code && $code) {
$this->code = $code;
}
}
}

View file

@ -0,0 +1,439 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Db
* @subpackage Statement
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Pdo.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* @see Zend_Db_Statement
*/
require_once 'Zend/Db/Statement.php';
/**
* Proxy class to wrap a PDOStatement object.
* Matches the interface of PDOStatement. All methods simply proxy to the
* matching method in PDOStatement. PDOExceptions thrown by PDOStatement
* are re-thrown as Zend_Db_Statement_Exception.
*
* @category Zend
* @package Zend_Db
* @subpackage Statement
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Db_Statement_Pdo extends Zend_Db_Statement implements IteratorAggregate
{
/**
* @var int
*/
protected $_fetchMode = PDO::FETCH_ASSOC;
/**
* Prepare a string SQL statement and create a statement object.
*
* @param string $sql
* @return void
* @throws Zend_Db_Statement_Exception
*/
protected function _prepare($sql)
{
try {
$this->_stmt = $this->_adapter->getConnection()->prepare($sql);
} catch (PDOException $e) {
require_once 'Zend/Db/Statement/Exception.php';
throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e);
}
}
/**
* Bind a column of the statement result set to a PHP variable.
*
* @param string $column Name the column in the result set, either by
* position or by name.
* @param mixed $param Reference to the PHP variable containing the value.
* @param mixed $type OPTIONAL
* @return bool
* @throws Zend_Db_Statement_Exception
*/
public function bindColumn($column, &$param, $type = null)
{
try {
if ($type === null) {
return $this->_stmt->bindColumn($column, $param);
} else {
return $this->_stmt->bindColumn($column, $param, $type);
}
} catch (PDOException $e) {
require_once 'Zend/Db/Statement/Exception.php';
throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e);
}
}
/**
* Binds a parameter to the specified variable name.
*
* @param mixed $parameter Name the parameter, either integer or string.
* @param mixed $variable Reference to PHP variable containing the value.
* @param mixed $type OPTIONAL Datatype of SQL parameter.
* @param mixed $length OPTIONAL Length of SQL parameter.
* @param mixed $options OPTIONAL Other options.
* @return bool
* @throws Zend_Db_Statement_Exception
*/
protected function _bindParam($parameter, &$variable, $type = null, $length = null, $options = null)
{
try {
if ($type === null) {
if (is_bool($variable)) {
$type = PDO::PARAM_BOOL;
} elseif ($variable === null) {
$type = PDO::PARAM_NULL;
} elseif (is_integer($variable)) {
$type = PDO::PARAM_INT;
} else {
$type = PDO::PARAM_STR;
}
}
return $this->_stmt->bindParam($parameter, $variable, $type, $length, $options);
} catch (PDOException $e) {
require_once 'Zend/Db/Statement/Exception.php';
throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e);
}
}
/**
* Binds a value to a parameter.
*
* @param mixed $parameter Name the parameter, either integer or string.
* @param mixed $value Scalar value to bind to the parameter.
* @param mixed $type OPTIONAL Datatype of the parameter.
* @return bool
* @throws Zend_Db_Statement_Exception
*/
public function bindValue($parameter, $value, $type = null)
{
if (is_string($parameter) && $parameter[0] != ':') {
$parameter = ":$parameter";
}
$this->_bindParam[$parameter] = $value;
try {
if ($type === null) {
return $this->_stmt->bindValue($parameter, $value);
} else {
return $this->_stmt->bindValue($parameter, $value, $type);
}
} catch (PDOException $e) {
require_once 'Zend/Db/Statement/Exception.php';
throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e);
}
}
/**
* Closes the cursor, allowing the statement to be executed again.
*
* @return bool
* @throws Zend_Db_Statement_Exception
*/
public function closeCursor()
{
try {
return $this->_stmt->closeCursor();
} catch (PDOException $e) {
require_once 'Zend/Db/Statement/Exception.php';
throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e);
}
}
/**
* Returns the number of columns in the result set.
* Returns null if the statement has no result set metadata.
*
* @return int The number of columns.
* @throws Zend_Db_Statement_Exception
*/
public function columnCount()
{
try {
return $this->_stmt->columnCount();
} catch (PDOException $e) {
require_once 'Zend/Db/Statement/Exception.php';
throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e);
}
}
/**
* Retrieves the error code, if any, associated with the last operation on
* the statement handle.
*
* @return string error code.
* @throws Zend_Db_Statement_Exception
*/
public function errorCode()
{
try {
return $this->_stmt->errorCode();
} catch (PDOException $e) {
require_once 'Zend/Db/Statement/Exception.php';
throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e);
}
}
/**
* Retrieves an array of error information, if any, associated with the
* last operation on the statement handle.
*
* @return array
* @throws Zend_Db_Statement_Exception
*/
public function errorInfo()
{
try {
return $this->_stmt->errorInfo();
} catch (PDOException $e) {
require_once 'Zend/Db/Statement/Exception.php';
throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e);
}
}
/**
* Executes a prepared statement.
*
* @param array $params OPTIONAL Values to bind to parameter placeholders.
* @return bool
* @throws Zend_Db_Statement_Exception
*/
public function _execute(array $params = null)
{
try {
if ($params !== null) {
return $this->_stmt->execute($params);
} else {
return $this->_stmt->execute();
}
} catch (PDOException $e) {
require_once 'Zend/Db/Statement/Exception.php';
throw new Zend_Db_Statement_Exception($e->getMessage(), (int) $e->getCode(), $e);
}
}
/**
* Fetches a row from the result set.
*
* @param int $style OPTIONAL Fetch mode for this fetch operation.
* @param int $cursor OPTIONAL Absolute, relative, or other.
* @param int $offset OPTIONAL Number for absolute or relative cursors.
* @return mixed Array, object, or scalar depending on fetch mode.
* @throws Zend_Db_Statement_Exception
*/
public function fetch($style = null, $cursor = null, $offset = null)
{
if ($style === null) {
$style = $this->_fetchMode;
}
try {
return $this->_stmt->fetch($style, $cursor, $offset);
} catch (PDOException $e) {
require_once 'Zend/Db/Statement/Exception.php';
throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e);
}
}
/**
* Required by IteratorAggregate interface
*
* @return IteratorIterator
*/
public function getIterator()
{
return new IteratorIterator($this->_stmt);
}
/**
* Returns an array containing all of the result set rows.
*
* @param int $style OPTIONAL Fetch mode.
* @param int $col OPTIONAL Column number, if fetch mode is by column.
* @return array Collection of rows, each in a format by the fetch mode.
* @throws Zend_Db_Statement_Exception
*/
public function fetchAll($style = null, $col = null)
{
if ($style === null) {
$style = $this->_fetchMode;
}
try {
if ($style == PDO::FETCH_COLUMN) {
if ($col === null) {
$col = 0;
}
return $this->_stmt->fetchAll($style, $col);
} else {
return $this->_stmt->fetchAll($style);
}
} catch (PDOException $e) {
require_once 'Zend/Db/Statement/Exception.php';
throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e);
}
}
/**
* Returns a single column from the next row of a result set.
*
* @param int $col OPTIONAL Position of the column to fetch.
* @return string
* @throws Zend_Db_Statement_Exception
*/
public function fetchColumn($col = 0)
{
try {
return $this->_stmt->fetchColumn($col);
} catch (PDOException $e) {
require_once 'Zend/Db/Statement/Exception.php';
throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e);
}
}
/**
* Fetches the next row and returns it as an object.
*
* @param string $class OPTIONAL Name of the class to create.
* @param array $config OPTIONAL Constructor arguments for the class.
* @return mixed One object instance of the specified class.
* @throws Zend_Db_Statement_Exception
*/
public function fetchObject($class = 'stdClass', array $config = array())
{
try {
return $this->_stmt->fetchObject($class, $config);
} catch (PDOException $e) {
require_once 'Zend/Db/Statement/Exception.php';
throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e);
}
}
/**
* Retrieve a statement attribute.
*
* @param integer $key Attribute name.
* @return mixed Attribute value.
* @throws Zend_Db_Statement_Exception
*/
public function getAttribute($key)
{
try {
return $this->_stmt->getAttribute($key);
} catch (PDOException $e) {
require_once 'Zend/Db/Statement/Exception.php';
throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e);
}
}
/**
* Returns metadata for a column in a result set.
*
* @param int $column
* @return mixed
* @throws Zend_Db_Statement_Exception
*/
public function getColumnMeta($column)
{
try {
return $this->_stmt->getColumnMeta($column);
} catch (PDOException $e) {
require_once 'Zend/Db/Statement/Exception.php';
throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e);
}
}
/**
* Retrieves the next rowset (result set) for a SQL statement that has
* multiple result sets. An example is a stored procedure that returns
* the results of multiple queries.
*
* @return bool
* @throws Zend_Db_Statement_Exception
*/
public function nextRowset()
{
try {
return $this->_stmt->nextRowset();
} catch (PDOException $e) {
require_once 'Zend/Db/Statement/Exception.php';
throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e);
}
}
/**
* Returns the number of rows affected by the execution of the
* last INSERT, DELETE, or UPDATE statement executed by this
* statement object.
*
* @return int The number of rows affected.
* @throws Zend_Db_Statement_Exception
*/
public function rowCount()
{
try {
return $this->_stmt->rowCount();
} catch (PDOException $e) {
require_once 'Zend/Db/Statement/Exception.php';
throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e);
}
}
/**
* Set a statement attribute.
*
* @param string $key Attribute name.
* @param mixed $val Attribute value.
* @return bool
* @throws Zend_Db_Statement_Exception
*/
public function setAttribute($key, $val)
{
try {
return $this->_stmt->setAttribute($key, $val);
} catch (PDOException $e) {
require_once 'Zend/Db/Statement/Exception.php';
throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e);
}
}
/**
* Set the default fetch mode for this statement.
*
* @param int $mode The fetch mode.
* @return bool
* @throws Zend_Db_Statement_Exception
*/
public function setFetchMode($mode)
{
$this->_fetchMode = $mode;
try {
return $this->_stmt->setFetchMode($mode);
} catch (PDOException $e) {
require_once 'Zend/Db/Statement/Exception.php';
throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e);
}
}
}

View file

@ -0,0 +1,94 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Db
* @subpackage Statement
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Ibm.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* @see Zend_Db_Statement_Pdo
*/
require_once 'Zend/Db/Statement/Pdo.php';
/**
* Proxy class to wrap a PDOStatement object for IBM Databases.
* Matches the interface of PDOStatement. All methods simply proxy to the
* matching method in PDOStatement. PDOExceptions thrown by PDOStatement
* are re-thrown as Zend_Db_Statement_Exception.
*
* @category Zend
* @package Zend_Db
* @subpackage Statement
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Db_Statement_Pdo_Ibm extends Zend_Db_Statement_Pdo
{
/**
* Returns an array containing all of the result set rows.
*
* Behaves like parent, but if limit()
* is used, the final result removes the extra column
* 'zend_db_rownum'
*
* @param int $style OPTIONAL Fetch mode.
* @param int $col OPTIONAL Column number, if fetch mode is by column.
* @return array Collection of rows, each in a format by the fetch mode.
* @throws Zend_Db_Statement_Exception
*/
public function fetchAll($style = null, $col = null)
{
$data = parent::fetchAll($style, $col);
$results = array();
$remove = $this->_adapter->foldCase('ZEND_DB_ROWNUM');
foreach ($data as $row) {
if (is_array($row) && array_key_exists($remove, $row)) {
unset($row[$remove]);
}
$results[] = $row;
}
return $results;
}
/**
* Binds a parameter to the specified variable name.
*
* @param mixed $parameter Name the parameter, either integer or string.
* @param mixed $variable Reference to PHP variable containing the value.
* @param mixed $type OPTIONAL Datatype of SQL parameter.
* @param mixed $length OPTIONAL Length of SQL parameter.
* @param mixed $options OPTIONAL Other options.
* @return bool
* @throws Zend_Db_Statement_Exception
*/
public function _bindParam($parameter, &$variable, $type = null, $length = null, $options = null)
{
try {
if (($type === null) && ($length === null) && ($options === null)) {
return $this->_stmt->bindParam($parameter, $variable);
} else {
return $this->_stmt->bindParam($parameter, $variable, $type, $length, $options);
}
} catch (PDOException $e) {
require_once 'Zend/Db/Statement/Exception.php';
throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e);
}
}
}

View file

@ -0,0 +1,91 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Db
* @subpackage Statement
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Oci.php 21105 2010-02-19 21:27:09Z mikaelkael $
*/
/**
* @see Zend_Db_Statement_Pdo
*/
require_once 'Zend/Db/Statement/Pdo.php';
/**
* Proxy class to wrap a PDOStatement object for IBM Databases.
* Matches the interface of PDOStatement. All methods simply proxy to the
* matching method in PDOStatement. PDOExceptions thrown by PDOStatement
* are re-thrown as Zend_Db_Statement_Exception.
*
* @category Zend
* @package Zend_Db
* @subpackage Statement
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Db_Statement_Pdo_Oci extends Zend_Db_Statement_Pdo
{
/**
* Returns an array containing all of the result set rows.
*
* Behaves like parent, but if limit()
* is used, the final result removes the extra column
* 'zend_db_rownum'
*
* @param int $style OPTIONAL Fetch mode.
* @param int $col OPTIONAL Column number, if fetch mode is by column.
* @return array Collection of rows, each in a format by the fetch mode.
* @throws Zend_Db_Statement_Exception
*/
public function fetchAll($style = null, $col = null)
{
$data = parent::fetchAll($style, $col);
$results = array();
$remove = $this->_adapter->foldCase('zend_db_rownum');
foreach ($data as $row) {
if (is_array($row) && array_key_exists($remove, $row)) {
unset($row[$remove]);
}
$results[] = $row;
}
return $results;
}
/**
* Fetches a row from the result set.
*
* @param int $style OPTIONAL Fetch mode for this fetch operation.
* @param int $cursor OPTIONAL Absolute, relative, or other.
* @param int $offset OPTIONAL Number for absolute or relative cursors.
* @return mixed Array, object, or scalar depending on fetch mode.
* @throws Zend_Db_Statement_Exception
*/
public function fetch($style = null, $cursor = null, $offset = null)
{
$row = parent::fetch($style, $cursor, $offset);
$remove = $this->_adapter->foldCase('zend_db_rownum');
if (is_array($row) && array_key_exists($remove, $row)) {
unset($row[$remove]);
}
return $row;
}
}

View file

@ -0,0 +1,411 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Db
* @subpackage Statement
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Sqlsrv.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* @see Zend_Db_Statement
*/
require_once 'Zend/Db/Statement.php';
/**
* Extends for Microsoft SQL Server Driver for PHP
*
* @category Zend
* @package Zend_Db
* @subpackage Statement
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Db_Statement_Sqlsrv extends Zend_Db_Statement
{
/**
* The connection_stmt object original string.
*/
protected $_originalSQL;
/**
* Column names.
*/
protected $_keys;
/**
* Query executed
*/
protected $_executed = false;
/**
* Prepares statement handle
*
* @param string $sql
* @return void
* @throws Zend_Db_Statement_Sqlsrv_Exception
*/
protected function _prepare($sql)
{
$connection = $this->_adapter->getConnection();
$this->_stmt = sqlsrv_prepare($connection, $sql);
if (!$this->_stmt) {
require_once 'Zend/Db/Statement/Sqlsrv/Exception.php';
throw new Zend_Db_Statement_Sqlsrv_Exception(sqlsrv_errors());
}
$this->_originalSQL = $sql;
}
/**
* Binds a parameter to the specified variable name.
*
* @param mixed $parameter Name the parameter, either integer or string.
* @param mixed $variable Reference to PHP variable containing the value.
* @param mixed $type OPTIONAL Datatype of SQL parameter.
* @param mixed $length OPTIONAL Length of SQL parameter.
* @param mixed $options OPTIONAL Other options.
* @return bool
* @throws Zend_Db_Statement_Exception
*/
protected function _bindParam($parameter, &$variable, $type = null, $length = null, $options = null)
{
//Sql server doesn't support bind by name
return true;
}
/**
* Closes the cursor, allowing the statement to be executed again.
*
* @return bool
*/
public function closeCursor()
{
if (!$this->_stmt) {
return false;
}
sqlsrv_free_stmt($this->_stmt);
$this->_stmt = false;
return true;
}
/**
* Returns the number of columns in the result set.
* Returns null if the statement has no result set metadata.
*
* @return int The number of columns.
*/
public function columnCount()
{
if ($this->_stmt && $this->_executed) {
return sqlsrv_num_fields($this->_stmt);
}
return 0;
}
/**
* Retrieves the error code, if any, associated with the last operation on
* the statement handle.
*
* @return string error code.
*/
public function errorCode()
{
if (!$this->_stmt) {
return false;
}
$error = sqlsrv_errors();
if (!$error) {
return false;
}
return $error[0]['code'];
}
/**
* Retrieves an array of error information, if any, associated with the
* last operation on the statement handle.
*
* @return array
*/
public function errorInfo()
{
if (!$this->_stmt) {
return false;
}
$error = sqlsrv_errors();
if (!$error) {
return false;
}
return array(
$error[0]['code'],
$error[0]['message'],
);
}
/**
* Executes a prepared statement.
*
* @param array $params OPTIONAL Values to bind to parameter placeholders.
* @return bool
* @throws Zend_Db_Statement_Exception
*/
public function _execute(array $params = null)
{
$connection = $this->_adapter->getConnection();
if (!$this->_stmt) {
return false;
}
if ($params !== null) {
if (!is_array($params)) {
$params = array($params);
}
$error = false;
// make all params passed by reference
$params_ = array();
$temp = array();
$i = 1;
foreach ($params as $param) {
$temp[$i] = $param;
$params_[] = &$temp[$i];
$i++;
}
$params = $params_;
}
$this->_stmt = sqlsrv_query($connection, $this->_originalSQL, $params);
if (!$this->_stmt) {
require_once 'Zend/Db/Statement/Sqlsrv/Exception.php';
throw new Zend_Db_Statement_Sqlsrv_Exception(sqlsrv_errors());
}
$this->_executed = true;
return (!$this->_stmt);
}
/**
* Fetches a row from the result set.
*
* @param int $style OPTIONAL Fetch mode for this fetch operation.
* @param int $cursor OPTIONAL Absolute, relative, or other.
* @param int $offset OPTIONAL Number for absolute or relative cursors.
* @return mixed Array, object, or scalar depending on fetch mode.
* @throws Zend_Db_Statement_Exception
*/
public function fetch($style = null, $cursor = null, $offset = null)
{
if (!$this->_stmt) {
return false;
}
if (null === $style) {
$style = $this->_fetchMode;
}
$values = sqlsrv_fetch_array($this->_stmt, SQLSRV_FETCH_ASSOC);
if (!$values && (null !== $error = sqlsrv_errors())) {
require_once 'Zend/Db/Statement/Sqlsrv/Exception.php';
throw new Zend_Db_Statement_Sqlsrv_Exception($error);
}
if (null === $values) {
return null;
}
if (!$this->_keys) {
foreach ($values as $key => $value) {
$this->_keys[] = $this->_adapter->foldCase($key);
}
}
$values = array_values($values);
$row = false;
switch ($style) {
case Zend_Db::FETCH_NUM:
$row = $values;
break;
case Zend_Db::FETCH_ASSOC:
$row = array_combine($this->_keys, $values);
break;
case Zend_Db::FETCH_BOTH:
$assoc = array_combine($this->_keys, $values);
$row = array_merge($values, $assoc);
break;
case Zend_Db::FETCH_OBJ:
$row = (object) array_combine($this->_keys, $values);
break;
case Zend_Db::FETCH_BOUND:
$assoc = array_combine($this->_keys, $values);
$row = array_merge($values, $assoc);
$row = $this->_fetchBound($row);
break;
default:
require_once 'Zend/Db/Statement/Sqlsrv/Exception.php';
throw new Zend_Db_Statement_Sqlsrv_Exception("Invalid fetch mode '$style' specified");
break;
}
return $row;
}
/**
* Returns a single column from the next row of a result set.
*
* @param int $col OPTIONAL Position of the column to fetch.
* @return string
* @throws Zend_Db_Statement_Exception
*/
public function fetchColumn($col = 0)
{
if (!$this->_stmt) {
return false;
}
if (!sqlsrv_fetch($this->_stmt)) {
if (null !== $error = sqlsrv_errors()) {
require_once 'Zend/Db/Statement/Sqlsrv/Exception.php';
throw new Zend_Db_Statement_Sqlsrv_Exception($error);
}
// If no error, there is simply no record
return false;
}
$data = sqlsrv_get_field($this->_stmt, $col); //0-based
if ($data === false) {
require_once 'Zend/Db/Statement/Sqlsrv/Exception.php';
throw new Zend_Db_Statement_Sqlsrv_Exception(sqlsrv_errors());
}
return $data;
}
/**
* Fetches the next row and returns it as an object.
*
* @param string $class OPTIONAL Name of the class to create.
* @param array $config OPTIONAL Constructor arguments for the class.
* @return mixed One object instance of the specified class.
* @throws Zend_Db_Statement_Exception
*/
public function fetchObject($class = 'stdClass', array $config = array())
{
if (!$this->_stmt) {
return false;
}
$obj = sqlsrv_fetch_object($this->_stmt);
if ($error = sqlsrv_errors()) {
require_once 'Zend/Db/Statement/Sqlsrv/Exception.php';
throw new Zend_Db_Statement_Sqlsrv_Exception($error);
}
/* @todo XXX handle parameters */
if (null === $obj) {
return false;
}
return $obj;
}
/**
* Returns metadata for a column in a result set.
*
* @param int $column
* @return mixed
* @throws Zend_Db_Statement_Sqlsrv_Exception
*/
public function getColumnMeta($column)
{
$fields = sqlsrv_field_metadata($this->_stmt);
if (!$fields) {
throw new Zend_Db_Statement_Sqlsrv_Exception('Column metadata can not be fetched');
}
if (!isset($fields[$column])) {
throw new Zend_Db_Statement_Sqlsrv_Exception('Column index does not exist in statement');
}
return $fields[$column];
}
/**
* Retrieves the next rowset (result set) for a SQL statement that has
* multiple result sets. An example is a stored procedure that returns
* the results of multiple queries.
*
* @return bool
* @throws Zend_Db_Statement_Exception
*/
public function nextRowset()
{
if (sqlsrv_next_result($this->_stmt) === false) {
require_once 'Zend/Db/Statement/Sqlsrv/Exception.php';
throw new Zend_Db_Statement_Sqlsrv_Exception(sqlsrv_errors());
}
//else - moved to next (or there are no more rows)
}
/**
* Returns the number of rows affected by the execution of the
* last INSERT, DELETE, or UPDATE statement executed by this
* statement object.
*
* @return int The number of rows affected.
* @throws Zend_Db_Statement_Exception
*/
public function rowCount()
{
if (!$this->_stmt) {
return false;
}
if (!$this->_executed) {
return 0;
}
$num_rows = sqlsrv_rows_affected($this->_stmt);
// Strict check is necessary; 0 is a valid return value
if ($num_rows === false) {
require_once 'Zend/Db/Statement/Sqlsrv/Exception.php';
throw new Zend_Db_Statement_Sqlsrv_Exception(sqlsrv_errors());
}
return $num_rows;
}
}

View file

@ -0,0 +1,61 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Db
* @subpackage Statement
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* @see Zend_Db_Statement_Exception
*/
require_once 'Zend/Db/Statement/Exception.php';
/**
* @package Zend_Db
* @subpackage Statement
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Db_Statement_Sqlsrv_Exception extends Zend_Db_Statement_Exception
{
/**
* Constructor
*
* If $message is an array, the assumption is that the return value of
* sqlsrv_errors() was provided. If so, it then retrieves the most recent
* error from that stack, and sets the message and code based on it.
*
* @param null|array|string $message
* @param null|int $code
*/
public function __construct($message = null, $code = 0)
{
if (is_array($message)) {
// Error should be array of errors
// We only need first one (?)
if (isset($message[0])) {
$message = $message[0];
}
$code = (int) $message['code'];
$message = (string) $message['message'];
}
parent::__construct($message, $code);
}
}