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

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, 4 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 Bill Adams (bill<at>evil<dot>inetarena<dot>com)
4 DBD::Informix -- The Informix Driver.
5 See: http://evil.inetarena.com/php/DBI.php for more info.
6
7 Licence: LGPL (http://www.gnu.org/).
8
9 This software is provided "AS IS" with no warrenty either implicit,
10 explicit or otherwise. Use at your own risk.
11
12 07 May 2000 baa Added rows( ) function to STH object.
13
14 */
15
16 class DBD_Informix {
17
18 var $is_persisent;
19 var $errstr;
20 var $dbh;
21
22 function DBD_connect( $db_name, $db_host = '',
23 $db_user = '', $db_passwd = '',
24 $is_persistent = 0){
25 //Track the $is_persistent just for fun...
26 $is_persistent = $is_persistent ? $is_persistent : 0;
27 $this->is_persistent = $is_persistent;
28
29 //DEBUG...
30 echo "DBD::Informix: [$db_name][$db_host][$db_user][$is_persistent]<br>\n";
31
32 if( ! getenv( "INFORMIXDIR" ) || ! getenv( "INFORMIXSERVER" )){
33 if( ! getenv( "INFORMIXDIR" )){
34 echo "DBD::Informix -- No INFORMIXDIR set, put something like 'setenv( \"INFORMIXDIR=/path/to/informix\" );' in your program.<br>\n";
35 }
36 if( ! getenv( "INFORMIXSERVER" )){
37 echo "DBD::Informix -- No INFORMIXSERVER set, put something like 'setenv( \"INFORMIXSERVER=defaultserver\" );' in your program.<br>\n";
38 }
39
40 $this->errstr = "DBD::Informix -- Error, required Informix environment missing.";
41 return; }
42
43 if( $is_persistent ){
44 echo "Persistent Connection.\n";
45 $conn = ifx_pconnect( $db_name, $db_user, $db_passwd );
46 } else {
47 $conn = ifx_connect( $db_name, $db_user, $db_passwd );
48 }
49
50 if( ! $conn ){
51 $this->errstr = "DBD::Informix Error: Could not connect to $db_name";
52 return;
53 }
54
55 $this->dbh = $conn;
56 return( $this );
57 }//end connect function
58
59
60
61 function disconnect( ){
62 ifx_close( $this->dbh );
63 $this->dbh = undef;
64 return( 1 );
65 }//end disconnect function
66
67
68 function prepare( $query ){
69 if( ! $this->dbh ){ return; }
70 //Does nothing but save the query...
71 $sth = new STH_Informix;
72 $sth->DBH( $this );
73 $sth->prepare( $query );
74 return( $sth );
75 }//end dbh prepare fn
76
77
78 //do is a reserved word so I have to name this something else.
79 function dbh_do( $query ){
80 //run the query and return the number of affected rows.
81 $result = ifx_query( $query, $this->dbh );
82 if( ! $result ){
83 if( ereg( "SQLCODE=(-?[0-9]+)", ifx_error( $this->dbh ), $regs )){
84 $error_no = $regs[1];
85 if( $error_no == -201 ){
86 $error_message = "($error_no) Syntax Error";
87 }
88 } else {
89 $error_message = ifx_error( $this->dbh );
90 //$error_message = ifx_errormsg( $this->dbh );
91 }
92
93
94 $this->errstr = "DBI Error: 'dbh_do' failed: $error_message";
95 return;
96 }
97 $rows = ifx_affected_rows( $result ); //this->dbh );
98 $this->result = $result;
99 return( $rows );
100 }//end fn do
101
102
103 function insert_id( ){
104 //Get the last serial number from an insert.
105 $sqlca = ifx_getsqlca( $this->result );
106 return( $sqlca['sqlerrd1'] );
107 }//end fn do
108
109
110 function quote( $string ){
111 //In informix, to quote a single quote, double it. I do not
112 // know how other characters have to be quoted but it looks like they
113 // don't have to be...
114 if( $string ){
115 return( "'".ereg_replace( "'", "''", $string )."'" );
116 } else {
117 return( 'NULL' );
118 }
119 }//end fn quote
120 }//end DBI class
121
122
123 //===========================================================
124
125 class STH_Informix {
126
127 var $query;
128 var $DBH;
129 var $dbh;
130 var $result;
131
132 function STH_Informix( $dbh = '' ){
133 if( $dbh ){
134 $this->dbh = $dbh;
135 }
136 return( $this );
137 }
138
139
140 function DBH( $dbh ){
141 $this->DBH = $dbh;
142 $this->dbh = $dbh->dbh;
143 return( $dbh );
144 }
145
146
147 function prepare( $query ){
148 if( ! $this->dbh ){ return; }
149 $this->query = $query;
150 if( $this->result ){ ifx_free_result( $this->result ); }
151 $this->result = ifx_prepare( $query, $this->dbh, 0 );
152 if( ! $this->result ){
153 $this->errstr = "DBD::Informix: ".ifx_error( $this->dbh );
154 return;
155 }
156 return( $this->result );
157 }
158
159
160 function execute( ){
161 if( ! $this->dbh ){ return; }
162 if( ! $this->result ){ return; }
163 $worked = ifx_do( $this->result );
164 if( ! $worked ){
165 ifx_free_result( $this->result );
166 $this->errstr = "STH Execute failed: ".ifx_error( $this->dbh );
167 return;
168 }
169 return( 1 );
170 }//end execute fn
171
172
173 function finish( ){
174 if( ! $this->result ){ return; }
175 ifx_free_result( $this->result );
176 $this->result = undef;
177 return( 1 );
178 }//end execute fn
179
180
181 function rows( ){
182 if( ! $this->dbh ){ return; }
183 return ifx_num_rows( $this->result );
184 }
185
186
187
188 function fetchrow_array( ){
189 if( ! $this->result ){
190 //echo "STH Error: Calling fetchrow on null result.<br>\n";
191 return;
192 }
193 return( ifx_fetch_row( $this->result, "NEXT" ));
194 }
195
196
197 function fetchrow_hash( ){
198 if( ! $this->result ){
199 //echo "STH Error: Calling fetchrow on null result.<br>\n";
200 return;
201 }
202 return( ifx_fetch_row( $this->result ));
203 }
204 }
205
206
207 $GLOBALS[classDBDInformix_read] = 1;

  ViewVC Help
Powered by ViewVC 1.1.26