Go to the documentation of this file.00001 <?php
00002
00003 require 'firebirdResultset.php';
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 class firebirdStatement
00018 {
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 private $objAutoCommit;
00030
00031
00032
00033
00034
00035
00036
00037 private $objConnection;
00038
00039
00040
00041
00042
00043
00044
00045 private $objLimit = false;
00046
00047
00048
00049
00050
00051
00052
00053 private $objOffset = false;
00054
00055
00056
00057
00058
00059
00060
00061 private $objParameters = array();
00062
00063
00064
00065
00066
00067
00068
00069 private $objSavepoint;
00070
00071
00072
00073
00074
00075
00076
00077 private $objSequence = false;
00078
00079
00080
00081
00082
00083
00084
00085 private $objQuery;
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100 public function __construct( $query, $connection, $autocommit, $savepoint )
00101 {
00102 $this->objAutoCommit = $autocommit;
00103 $this->objConnection = $connection;
00104 $this->objSavepoint = $savepoint;
00105 $this->objQuery = $query;
00106 }
00107
00108
00109
00110
00111
00112
00113
00114
00115 function bind( $param, $no_quotes=false )
00116 {
00117
00118 if ( ( is_string( $param ) && !is_numeric( $param ) ) && !$no_quotes )
00119 {
00120 if ( get_magic_quotes_gpc() )
00121 $param = stripslashes( $param );
00122
00123 $param = str_replace( "'", "''", $param );
00124 $param = "'" . $param . "'";
00125 }
00126
00127 $this->objParameters[] = $param;
00128 }
00129
00130
00131
00132
00133
00134
00135
00136 public function execute()
00137 {
00138 if ( is_resource( $this->objAutoCommit ) && stripos( $this->objPrepareSQL(), 'select' ) === false )
00139 {
00140 if ( $this->objSavepoint )
00141 $objResult = ibase_query( $this->objSavepoint, $this->objPrepareSQL() )
00142 or trigger_error( ibase_errmsg(), E_USER_WARNING );
00143 else
00144 $objResult = ibase_query( $this->objAutoCommit, $this->objPrepareSQL() )
00145 or trigger_error( ibase_errmsg(), E_USER_WARNING );
00146 }
00147 else
00148 {
00149 $objResult = ibase_query( $this->objConnection->connection(), $this->objPrepareSQL() )
00150 or trigger_error( ibase_errmsg(), E_USER_WARNING );
00151 }
00152
00153 return new firebirdResultset( $objResult, $this->objConnection->connection() );
00154 }
00155
00156
00157
00158
00159
00160
00161
00162 public function limit( $limit )
00163 {
00164
00165 $this->objLimit = ( is_numeric( $limit ) && $limit > 0 ) ? ( int )$limit : 1;
00166 }
00167
00168
00169
00170
00171
00172
00173
00174 public function objExecuteNonPrepared()
00175 {
00176 if ( is_resource( $this->objAutoCommit ) && stripos( $this->objQuery, 'select' ) === false )
00177 {
00178 if ( $this->objSavepoint )
00179 $objResult = ibase_query( $this->objSavepoint, $this->objQuery )
00180 or trigger_error( ibase_errmsg(), E_USER_WARNING );
00181 else
00182 $objResult = ibase_query( $this->objAutoCommit, $this->objQuery )
00183 or trigger_error( ibase_errmsg(), E_USER_WARNING );
00184 }
00185 else
00186 {
00187 $objResult = ibase_query( $this->objConnection->connection(), $this->objQuery )
00188 or trigger_error( ibase_errmsg(), E_USER_WARNING );
00189 }
00190
00191 return new firebirdResultset( $objResult, $this->objConnection->connection() );
00192 }
00193
00194
00195
00196
00197
00198
00199
00200 private function objPrepareSQL()
00201 {
00202 $objSqlParts = explode( '?', $this->objQuery );
00203 $objQuery = $objSqlParts[0];
00204
00205 for ( $i = 1; $i < count( $objSqlParts ); $i++ )
00206 $objQuery .= $this->objParameters[$i - 1] . $objSqlParts[$i];
00207
00208 $objQuery = ( $this->objLimit ) ? str_ireplace( ':limit', $this->objLimit, $objQuery ) : $objQuery;
00209 $objQuery = ( $this->objOffset ) ? str_ireplace( ':offset', $this->objOffset, $objQuery ) : $objQuery;
00210 $objQuery = ( $this->objSequence ) ? str_ireplace( ':seq', $this->objSequence, $objQuery ) : $objQuery;
00211
00212 return $objQuery;
00213 }
00214
00215
00216
00217
00218
00219
00220
00221 public function offset( $offset )
00222 {
00223
00224 $this->objOffset = ( is_numeric( $offset ) && $offset > 0 ) ? ( int )$offset : 1;
00225 }
00226
00227
00228
00229
00230
00231
00232
00233 public function sequence( $sequence )
00234 {
00235 $this->objSequence = ibase_gen_id( $sequence, 1, $this->objConnection->connection() );
00236 }
00237 }
00238
00239 ?>