/[informatika.old]/html/inc/class.DBD::interbase
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 /html/inc/class.DBD::interbase

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.2.2 - (show annotations)
Mon Jul 31 18:31:36 2000 UTC (23 years, 9 months ago) by dpavlin
Branch: dbi
Changes since 1.1.2.1: +6 -5 lines
rows() support

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

  ViewVC Help
Powered by ViewVC 1.1.26