/[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

Annotation of /html/inc/class.DBD::interbase

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.2.4 - (hide annotations)
Wed Aug 2 12:44:16 2000 UTC (23 years, 9 months ago) by dpavlin
Branch: dbi
Changes since 1.1.2.3: +23 -11 lines
clustering of cludged cgi (can be turned off by $dbh->enable_sql_cludge=0; )
support for return values with lowercase column names

1 dpavlin 1.1.2.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 dpavlin 1.1.2.4 var $enable_cludge_sql = 1; // enable by default
26 dpavlin 1.1.2.1 var $dbh;
27    
28     function DBD_connect( $db_name, $db_host = '',
29     $db_user = '', $db_passwd = '',
30     $is_persistent = 0){
31    
32     //Track the $is_persistant just for fun...
33     $is_persistent = $is_persistent ? $is_persistent : 0;
34     $this->is_persistent = $is_persistent;
35    
36     //DEBUG...
37     echo "DBD::interbase: [$db_name][$db_host][$db_user][$is_persistent]<br>\n";
38    
39 dpavlin 1.1.2.3 $conn = array('','','');
40 dpavlin 1.1.2.1
41     if ($db_name) $conn[0] = $db_name ; # can have hostname inside!
42     if ($db_host) $conn[0] = "$db_host:$db_name" ;
43     if ($db_user) $conn[1] = $db_user ;
44     if ($db_passwd) $conn[2] = $db_passwd ;
45    
46     if( $is_persistent ){
47     $conn = ibase_pconnect( $conn[0],$conn[1],$conn[2] );
48     } else {
49     $conn = ibase_connect( $conn[0],$conn[1],$conn[2] );
50     }
51    
52     if( !$conn ){
53     $this->errstr = "DBD::interbase Error: Could not connect to the database.";
54     return;
55     }
56    
57     $this->dbh = $conn;
58     return( $this );
59     }//end connect function
60    
61    
62    
63     function disconnect( ){
64     ibase_close( $this->dbh );
65     $this->dbh = undef;
66     return( 1 );
67     }//end disconnect function
68    
69 dpavlin 1.1.2.4 function cludge_sql ( $query ) {
70     if ($this->$enable_cludge_sql) {
71     //cludge for "=true|false" and "is true|false"
72     $query=eregi_replace("= *true","='t'",$query);
73     $query=eregi_replace("= *false","='f'",$query);
74     $query=eregi_replace("is *true","='t'",$query);
75     $query=eregi_replace("is *false","='f'",$query);
76     //cludge for limit
77     $query=eregi_replace("limit.+","",$query);
78     }
79     return $query;
80     }
81 dpavlin 1.1.2.1
82     function prepare( $query ){
83     if( ! $this->dbh ){ return; }
84     //Does nothing but save the query...
85     $sth = new STH_interbase;
86     $sth->DBH( $this );
87 dpavlin 1.1.2.4 $sth->prepare( $this->cludge_sql($query) );
88 dpavlin 1.1.2.1 return( $sth );
89     }//end dbh prepare fn
90    
91    
92     //do is a reserved word so I have to name this something else.
93     function dbh_do( $query ){
94     //run the query and return the number of affected rows.
95 dpavlin 1.1.2.4 $result = ibase_query( $this->dbh, $this->cludge_sql($query) );
96 dpavlin 1.1.2.1 if( ! $result ){
97     $this->errstr = "DBI Error: 'dbh_do' failed: ".
98     ibase_errmsg( $this->dbh );
99    
100     if( $this->exit_on_fail ){
101     echo $this->errstr."<br>\n";
102     $this->disconnect( );
103     exit( ); }
104    
105     return;
106     }
107 dpavlin 1.1.2.2 $rows = ibase_num_fields( $result );
108 dpavlin 1.1.2.1 if( $rows == 0 ){ $rows = '0E0'; }
109     return( $rows );
110     }//end fn do
111    
112    
113     function insert_id( ){
114     //Get the last serial number from an insert.
115     $this->errstr = "DBI Error: 'insertid' unimplemented.";
116     return( -1 );
117     }//end fn do
118    
119    
120     function quote( $string ){
121     if( $string ){
122     return( "'".addslashes( $string )."'" );
123     } else {
124     return( 'NULL' );
125     }
126     }//end fn quote
127    
128    
129     }//end DBI class
130    
131    
132     //===========================================================
133    
134     class STH_interbase {
135    
136     var $query;
137     var $DBH;
138     var $dbh;
139     var $result;
140     var $row = 0;
141    
142     function STH( $dbh = '' ){
143     if( $dbh ){
144     $this->dbh = $dbh;
145     }
146     return( $this );
147     }
148    
149    
150     function DBH( $dbh ){
151     $this->DBH = $dbh; //watch out, this copies the object not the reference.
152     $this->dbh = $dbh->dbh;
153     return( $dbh );
154     }
155    
156    
157     function prepare( $query ){
158     if( ! $this->dbh ){ return; }
159     $this->query = $query;
160     return( $query );
161     }
162    
163    
164     function execute( ){
165     if( ! $this->dbh ){ return; }
166 dpavlin 1.1.2.4 // echo "Running query $this->query<br>\n";
167 dpavlin 1.1.2.2 $this->result = ibase_query( $this->dbh, $this->query );
168 dpavlin 1.1.2.1 if( ! $this->result ){
169     $this->errstr = "STH Execute failed: ".ibase_errmsg( $this->dbh );
170     return;
171     }
172    
173     return( 1 );
174     }//end execute fn
175    
176    
177     function finish( ){
178     if( ! $this->result ){ return; }
179     ibase_freeresult( $this->result );
180     $this->result = undef;
181     return( 1 );
182     }//end execute fn
183    
184    
185     function rows( ){
186 dpavlin 1.1.2.2 return( ibase_num_fields( $this->result ) );
187 dpavlin 1.1.2.1 } //end rows fn
188    
189     function fetchrow_array( ){
190     if( ! $this->result ){
191     //echo "STH Error: Calling fetchrow on null result.<br>\n";
192     return;
193     }
194 dpavlin 1.1.2.2 return( ibase_fetch_row( $this->result ));
195 dpavlin 1.1.2.1 }
196    
197    
198     function fetchrow_hash( ){
199     if( ! $this->result ){
200     //echo "STH Error: Calling fetchrow on null result.<br>\n";
201     return;
202     }
203 dpavlin 1.1.2.4 if (! $ret = ibase_fetch_object( $this->result )) return 0;
204     // cludge to make column names lowercase
205     while ($tmp = each($ret)) {
206     $row[ strtolower($tmp[0]) ] = $tmp[1] ; // lower case
207     $row[ $tmp[0] ] = $tmp[1] ; // upper case
208     }
209     return ( $row );
210 dpavlin 1.1.2.1 }
211     }
212    
213    
214     $GLOBALS[classDBDinterbase_read] = 1;

  ViewVC Help
Powered by ViewVC 1.1.26