3 // +----------------------------------------------------------------------+
5 // +----------------------------------------------------------------------+
6 // | Copyright (c) 1997-2002 The PHP Group |
7 // +----------------------------------------------------------------------+
8 // | This source file is subject to version 2.02 of the PHP license, |
9 // | that is bundled with this package in the file LICENSE, and is |
10 // | available at through the world-wide-web at |
11 // | http://www.php.net/license/2_02.txt. |
12 // | If you did not receive a copy of the PHP license and are unable to |
13 // | obtain it through the world-wide-web, please send a note to |
14 // | license@php.net so we can mail you a copy immediately. |
15 // +----------------------------------------------------------------------+
16 // | Author: Sterling Hughes <sterling@php.net> |
17 // +----------------------------------------------------------------------+
19 // $Id: sybase.php,v 1.2 2004-04-26 20:44:37 rurban Exp $
21 // Database independent query interface definition for PHP's Sybase
24 // Based on DB 1.3 from the pear.php.net repository.
25 // The only modifications made have been modification of the include paths.
27 rcs_id('$Id: sybase.php,v 1.2 2004-04-26 20:44:37 rurban Exp $');
28 rcs_id('From Pear CVS: Id: sybase.php,v 1.3 2002/05/09 12:29:53 ssb Exp');
30 require_once 'DB/common.php';
32 class DB_sybase extends DB_common
37 var $phptype, $dbsyntax;
38 var $prepare_tokens = array();
39 var $prepare_types = array();
47 $this->phptype = 'sybase';
48 $this->dbsyntax = 'sybase';
49 $this->features = array(
52 'transactions' => false,
60 function connect($dsninfo, $persistent = false)
62 if (!DB::assertExtension('sybase') && !DB::assertExtension('sybase_ct'))
63 return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND);
65 $this->dsn = $dsninfo;
66 $user = $dsninfo['username'];
67 $pw = $dsninfo['password'];
69 $dbhost = $dsninfo['hostspec'] ? $dsninfo['hostspec'] : 'localhost';
70 $connect_function = $persistent ? 'sybase_pconnect' : 'sybase_connect';
72 if ($dbhost && $user && $pw) {
73 $conn = $connect_function($dbhost, $user, $pw);
74 } elseif ($dbhost && $user) {
75 $conn = $connect_function($dbhost, $user);
77 $conn = $connect_function($dbhost);
79 $conn = $connect_function();
83 return $this->raiseError(DB_ERROR_CONNECT_FAILED);
86 if ($dsninfo['database']) {
87 if (!@sybase_select_db($dsninfo['database'], $conn)) {
88 return $this->raiseError(DB_ERROR_NODBSELECTED);
91 $this->connection = $conn;
100 $ret = @sybase_close($this->connection);
101 $this->connection = null;
108 function simpleQuery($query)
110 $this->last_query = $query;
111 $query = $this->modifyQuery($query);
112 $result = @sybase_query($query, $this->connection);
114 return $this->raiseError();
116 // Determine which queries that should return data, and which
117 // should return an error code only.
118 return DB::isManip($query) ? DB_OK : $result;
125 * Move the internal sybase result pointer to the next available result
127 * @param a valid fbsql result resource
131 * @return true if a result is available otherwise return false
133 function nextResult($result)
140 function &fetchRow($result, $fetchmode = DB_FETCHMODE_DEFAULT, $rownum=null)
142 if ($fetchmode == DB_FETCHMODE_DEFAULT) {
143 $fetchmode = $this->fetchmode;
145 $res = $this->fetchInto ($result, $arr, $fetchmode, $rownum);
146 if ($res !== DB_OK) {
155 function fetchInto($result, &$ar, $fetchmode, $rownum=null)
157 if ($rownum !== null) {
158 if (!sybase_data_seek($result, $rownum)) {
159 return $this->raiseError();
162 $ar = ($fetchmode & DB_FETCHMODE_ASSOC) ? @sybase_fetch_array($result) : @sybase_fetch_row($result);
164 // reported not work as seems that sybase_get_last_message()
165 // always return a message here
166 //if ($errmsg = sybase_get_last_message()) {
167 // return $this->raiseError($errmsg);
178 function freeResult($result)
180 if (is_resource($result)) {
181 return @sybase_free_result($result);
183 if (!isset($this->prepare_tokens[(int)$result])) {
186 unset($this->prepare_tokens[(int)$result]);
187 unset($this->prepare_types[(int)$result]);
194 function numCols($result)
196 $cols = @sybase_num_fields($result);
198 return $this->raiseError();
204 // {{{ affectedRows()
207 * Gets the number of rows affected by the data manipulation
208 * query. For other queries, this function returns 0.
210 * @return number of rows affected by the last query
213 function affectedRows()
215 if (DB::isManip($this->last_query)) {
216 $result = @sybase_affected_rows($this->connection);
224 // {{{ getSpecialQuery()
227 * Returns the query needed to get some backend info
228 * @param string $type What kind of info you want to retrieve
229 * @return string The SQL query string
231 function getSpecialQuery($type)
235 $sql = "select name from sysobjects where type = 'U' order by name";
238 $sql = "select name from sysobjects where type = 'V'";