/[inncomm]/inc/class.DBD::sybase
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /inc/class.DBD::sybase

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.1.1 - (show annotations) (vendor branch)
Sat Nov 25 17:41:43 2000 UTC (23 years, 5 months ago) by dpavlin
Branch: DbP, MAIN
CVS Tags: r0, HEAD
Changes since 1.1: +0 -0 lines
first, semi-working version

1 <?PHP // -*-Mode: C++;-*-
2 /*
3 Roland Lichti (roland<at>lichti<dot>de)
4 DBD::sybase -- The Sybase Driver.
5 See: http://evil.inetarena.com/php/DBI.php for more info.
6
7 on basis of
8 Bill Adams (bill<at>evil<dot>inetarena<dot>com)
9 DBD::sybase -- The MySQL Driver.
10
11 Licence: LGPL (http://www.gnu.org/).
12
13 This software is provided "AS IS" with no warrenty either implicit,
14 explicit or otherwise. Use at your own risk.
15
16 Notes:
17
18 o insert_id is not implemented in sybase.
19
20 18 Mar 2000 rtl Created sybase-driver
21 17 Mar 2000 baa Moved the DBD stuff into their own class files.
22 07 May 2000 baa Added rows( ) STH function.
23
24 */
25
26 class DBD_sybase {
27
28 var $is_persisent;
29 var $DBI;
30 var $exit_on_fail = 0;
31
32 function DBD_connect( $db_name, $db_host = '',
33 $db_user = '', $db_passwd = '',
34 $is_persistent = 0){
35
36 //Track the $is_persistant just for fun...
37 $is_persistent = $is_persistent ? $is_persistent : 0;
38 $this->is_persistent = $is_persistent;
39
40 //DEBUG...
41 echo "DBD::sybase: [$db_name][$db_host][$db_user][$is_persistent]<br>\n";
42
43
44 if( $is_persistent ){
45 $conn = sybase_pconnect( $db_host, $db_user, $db_passwd );
46 } else {
47 $conn = sybase_connect( $db_host, $db_user, $db_passwd );
48 }
49
50 if( !$conn ){
51 $this->errstr = "DBD::sybase Error: Could not connect to the database.";
52 return;
53 }
54
55 if( ! sybase_select_db( $db_name, $conn )){
56 $this->errstr = "DBD::sybase Error: Could not select the database.<br>\n";
57 return;
58 }
59 $this->dbh = $conn;
60 return( $this );
61 }//end connect function
62
63
64
65 function disconnect( ){
66 sybase_close( $this->dbh );
67 $this->dbh = undef;
68 return( 1 );
69 }//end disconnect function
70
71
72 function prepare( $query ){
73 if( ! $this->dbh ){ return; }
74 //Does nothing but save the query...
75 $sth = new STH_sybase;
76 $sth->DBH( $this );
77 $sth->prepare( $query );
78 return( $sth );
79 }//end dbh prepare fn
80
81
82 //do is a reserved word so I have to name this something else.
83 function dbh_do( $query ){
84 //run the query and return the number of affected rows.
85 $result = sybase_query( $query, $this->dbh );
86 if( ! $result ){
87 $this->errstr = "DBI Error: 'dbh_do' failed.";
88
89 if( $this->exit_on_fail ){
90 echo $this->errstr."<br>\n";
91 $this->disconnect( );
92 exit( ); }
93
94 return;
95 }
96 $rows = sybase_affected_rows( $this->dbh );
97 return( $rows );
98 }//end fn do
99
100
101 function insert_id( ){
102 //Get the last serial number from an insert.
103 $this->errstr = "DBI Error: 'insert_id' unimplemented.";
104 return(-1);
105 }//end fn do
106
107
108 function quote( $string ){
109 if( $string ){
110 return( "'".addslashes( $string )."'" );
111 } else {
112 return( 'NULL' );
113 }
114 }//end fn quote
115
116
117 }//end DBI class
118
119
120 //===========================================================
121
122 class STH_sybase {
123
124 var $query;
125 var $DBH;
126 var $dbh;
127 var $result;
128
129 function STH( $dbh = '' ){
130 if( $dbh ){
131 $this->dbh = $dbh;
132 }
133 return( $this );
134 }
135
136
137 function DBH( $dbh ){
138 $this->DBH = $dbh;
139 $this->dbh = $dbh->dbh;
140 return( $dbh );
141 }
142
143
144 function prepare( $query ){
145 if( ! $this->dbh ){ return; }
146 $this->query = $query;
147 return( $query );
148 }
149
150
151 function execute( ){
152 if( ! $this->dbh ){ return; }
153
154 $this->result = sybase_query( $this->query, $this->dbh );
155
156 if( ! $this->result ){
157 $this->errstr = "STH Execute failed (" . $this->query . ").";
158 return;
159 }
160 return( 1 );
161 }//end execute fn
162
163
164 function finish( ){
165 if( ! $this->result ){ return; }
166 sybase_free_result( $this->result );
167 $this->result = undef;
168 return( 1 );
169 }//end execute fn
170
171
172 function rows( ){
173 if( ! $this->dbh ){ return; }
174 return sybase_num_rows( $this->result );
175 }
176
177
178 function fetchrow_array( ){
179 if( ! $this->result ){
180 //echo "STH Error: Calling fetchrow on null result.<br>\n";
181 return;
182 }
183 return( sybase_fetch_row( $this->result ));
184 }
185
186
187 function fetchrow_hash( ){
188 if( ! $this->result ){
189 //echo "STH Error: Calling fetchrow on null result.<br>\n";
190 return;
191 }
192
193 return( sybase_fetch_array( $this->result ));
194 }
195 }
196
197
198 $GLOBALS[classDBDsybase_read] = 1;

  ViewVC Help
Powered by ViewVC 1.1.26