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

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 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 if( $is_persistent ){
46 $conn = ibase_pconnect( $conn[0],$conn[1],$conn[2] );
47 } else {
48 $conn = ibase_connect( $conn[0],$conn[1],$conn[2] );
49 }
50
51 if( !$conn ){
52 $this->errstr = "DBD::interbase Error: Could not connect to the database.";
53 return;
54 }
55
56 $this->dbh = $conn;
57 return( $this );
58 }//end connect function
59
60
61
62 function disconnect( ){
63 ibase_close( $this->dbh );
64 $this->dbh = undef;
65 return( 1 );
66 }//end disconnect function
67
68
69 function prepare( $query ){
70 if( ! $this->dbh ){ return; }
71 //Does nothing but save the query...
72 $sth = new STH_interbase;
73 $sth->DBH( $this );
74 //cludge for "=true" and "is true"
75 $query=eregi_replace("= *true","='t'",$query);
76 $query=eregi_replace("is *true","='t'",$query);
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 //cludge for "=true" and "is true"
86 $query=eregi_replace("= *true","='t'",$query);
87 $query=eregi_replace("is *true","='t'",$query);
88 $result = ibase_query( $this->dbh, $query );
89 if( ! $result ){
90 $this->errstr = "DBI Error: 'dbh_do' failed: ".
91 ibase_errmsg( $this->dbh );
92
93 if( $this->exit_on_fail ){
94 echo $this->errstr."<br>\n";
95 $this->disconnect( );
96 exit( ); }
97
98 return;
99 }
100 $rows = ibase_num_fields( $result );
101 if( $rows == 0 ){ $rows = '0E0'; }
102 return( $rows );
103 }//end fn do
104
105
106 function insert_id( ){
107 //Get the last serial number from an insert.
108 $this->errstr = "DBI Error: 'insertid' unimplemented.";
109 return( -1 );
110 }//end fn do
111
112
113 function quote( $string ){
114 if( $string ){
115 return( "'".addslashes( $string )."'" );
116 } else {
117 return( 'NULL' );
118 }
119 }//end fn quote
120
121
122 }//end DBI class
123
124
125 //===========================================================
126
127 class STH_interbase {
128
129 var $query;
130 var $DBH;
131 var $dbh;
132 var $result;
133 var $row = 0;
134
135 function STH( $dbh = '' ){
136 if( $dbh ){
137 $this->dbh = $dbh;
138 }
139 return( $this );
140 }
141
142
143 function DBH( $dbh ){
144 $this->DBH = $dbh; //watch out, this copies the object not the reference.
145 $this->dbh = $dbh->dbh;
146 return( $dbh );
147 }
148
149
150 function prepare( $query ){
151 if( ! $this->dbh ){ return; }
152 $this->query = $query;
153 return( $query );
154 }
155
156
157 function execute( ){
158 if( ! $this->dbh ){ return; }
159 //echo "Running query $this->query<br>\n";
160 $this->result = ibase_query( $this->dbh, $this->query );
161 if( ! $this->result ){
162 $this->errstr = "STH Execute failed: ".ibase_errmsg( $this->dbh );
163 return;
164 }
165
166 return( 1 );
167 }//end execute fn
168
169
170 function finish( ){
171 if( ! $this->result ){ return; }
172 ibase_freeresult( $this->result );
173 $this->result = undef;
174 return( 1 );
175 }//end execute fn
176
177
178 function rows( ){
179 return( ibase_num_fields( $this->result ) );
180 } //end rows fn
181
182 function fetchrow_array( ){
183 if( ! $this->result ){
184 //echo "STH Error: Calling fetchrow on null result.<br>\n";
185 return;
186 }
187 return( ibase_fetch_row( $this->result ));
188 }
189
190
191 function fetchrow_hash( ){
192 if( ! $this->result ){
193 //echo "STH Error: Calling fetchrow on null result.<br>\n";
194 return;
195 }
196 // if ($this->row >= ibase_num_fields($this->result)) return 0;
197 return( ibase_fetch_object( $this->result ));
198 }
199 }
200
201
202 $GLOBALS[classDBDinterbase_read] = 1;

  ViewVC Help
Powered by ViewVC 1.1.26