Source for file odbc.php
Documentation is available at odbc.php
/* vim: set expandtab tabstop=4 shiftwidth=4 foldmethod=marker: */
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2004 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.02 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/2_02.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Author: Stig Bakken <ssb@php.net> |
// | Maintainer: Daniel Convissor <danielc@php.net> |
// +----------------------------------------------------------------------+
// $Id: odbc.php,v 1.46 2004/03/11 04:20:11 danielc Exp $
// More info on ODBC errors could be found here:
// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/trblsql/tr_err_odbc_5stz.asp
// XXX ERRORMSG: The error message from the odbc function should
require_once 'DB/common.php';
* Database independent query interface definition for PHP's ODBC
* @version $Id: odbc.php,v 1.46 2004/03/11 04:20:11 danielc Exp $
* @author Stig Bakken <ssb@php.net>
* Connect to a database and log in as the specified user.
* @param $dsn the data source name (see DB::parseDSN for syntax)
* @param $persistent (optional) whether the connection should
* @return int DB_OK on success, a DB error code on failure
function connect($dsninfo, $persistent = false )
if ($dsninfo['dbsyntax']) {
// the Navision driver doesn't support fetch row by number
* This is hear for backwards compatibility.
* Should have been using 'database' all along, but used hostspec.
if ($dsninfo['database']) {
$odbcdsn = $dsninfo['database'];
} elseif ($dsninfo['hostspec']) {
$odbcdsn = $dsninfo['hostspec'];
$connect_function = $persistent ? 'odbc_pconnect' : 'odbc_connect';
$connect_function = 'odbc_connect';
$conn = @$connect_function($odbcdsn, $dsninfo['username'],
* Send a query to ODBC and return the results as a ODBC resource
* @param $query the SQL query
* @return int returns a valid ODBC result for successful SELECT
* queries, DB_OK for other successful queries. A DB error code
* is returned on failure.
$query = $this->modifyQuery ($query);
// Determine which queries that should return data, and which
// should return an error code only.
$this->manip_result = $result; // For affectedRows()
$this->row[(int) $result] = 0;
* Move the internal odbc result pointer to the next available result
* @param a valid fbsql result resource
* @return true if a result is available otherwise return false
return @odbc_next_result ($result);
* Fetch a row and insert the data into an existing array.
* Formating of the array and the data therein are configurable.
* See DB_result::fetchInto() for more information.
* @param resource $result query result identifier
* @param array $arr (reference) array where data from the row
* @param int $fetchmode how the resulting array should be indexed
* @param int $rownum the row number to fetch
* @return mixed DB_OK on success, null when end of result set is
* @see DB_result::fetchInto()
function fetchInto ($result, &$arr, $fetchmode, $rownum=null )
$rownum++; // ODBC first row is 1
$cols = @odbc_fetch_into ($result, $arr, $rownum);
$cols = @odbc_fetch_into ($result, $rownum, $arr);
$cols = @odbc_fetch_into ($result, $arr);
/* XXX FIXME: doesn't work with unixODBC and easysoft
(get corrupted $errno values)
if ($errno = @odbc_error($this->connection)) {
return $this->RaiseError($errno);
for ($i = 0; $i < count($arr); $i++ ) {
$colName = @odbc_field_name ($result, $i+1 );
$this->_rtrimArrayValues ($arr);
$this->_convertNullArrayValuesToEmpty ($arr);
unset ($this->row[(int) $result]);
return @odbc_free_result ($result);
$cols = @odbc_num_fields ($result);
* Returns the number of rows affected by a manipulative query
* (INSERT, DELETE, UPDATE)
* @return mixed int affected rows, 0 when non manip queries or
if (empty ($this->manip_result)) { // In case of SELECT stms
$nrows = @odbc_num_rows ($this->manip_result);
* ODBC may or may not support counting rows in the result set of
* @param $result the odbc result resource
* @return the number of rows, or 0
$nrows = @odbc_num_rows ($result);
* Quote a string so it can be safely used as a table / column name
* Quoting style depends on which dbsyntax was passed in the DSN.
* Use 'mssql' as the dbsyntax in the DB DSN only if you've unchecked
* "Use ANSI quoted identifiers" when setting up the ODBC data source.
* @param string $str identifier name to be quoted
* @return string quoted identifier string
switch ($this->dsn['dbsyntax']) {
* @deprecated Deprecated in release 1.6.0
* Get the native error code of the last error (if any) that
* occured on the current connection.
* @return int ODBC error code
return @odbc_error () . ' ' . @odbc_errormsg ();
* Returns the next free id in a sequence
* @param string $seq_name name of the sequence
* @param boolean $ondemand when true, the seqence is automatically
* created if it does not exist
* @return int the next id number in the sequence. DB_Error if problem.
* @see DB_common::nextID()
function nextId($seq_name, $ondemand = true )
$seqname = $this->getSequenceName ($seq_name);
$this->pushErrorHandling (PEAR_ERROR_RETURN );
$result = $this->query(" update ${seqname} set id = id + 1" );
$this->popErrorHandling ();
$this->pushErrorHandling (PEAR_ERROR_RETURN );
$this->popErrorHandling ();
$result = $this->query(" insert into ${seqname} (id) values(0)" );
$result = $this->query(" select id from ${seqname}" );
* @param string $seq_name name of the new sequence
* @return int DB_OK on success. A DB_Error object is returned if
* @see DB_common::createSequence()
$seqname = $this->getSequenceName ($seq_name);
return $this->query(" CREATE TABLE ${seqname} ".
* @param string $seq_name name of the sequence to be deleted
* @return int DB_OK on success. DB_Error if problems.
* @see DB_common::dropSequence()
$seqname = $this->getSequenceName ($seq_name);
return $this->query(" DROP TABLE ${seqname}" );
if (!@odbc_autocommit ($this->connection, $onoff)) {
* Gather information about an error, then use that info to create a
* DB error object and finally return that object.
* @param integer $errno PEAR error number (usually a DB constant) if
* manually raising an error
* @return object DB error object
* @see DB_common::errorCode()
* @see DB_common::raiseError()
// Doing this in case mode changes during runtime.
return $this->raiseError($errno, null , null , null ,
Documentation generated on Mon, 11 Mar 2019 10:14:54 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|