@@ -179,61 +179,65 @@ private function processQueryResult(string $query, $result = null)
179179
180180 // Query was an insert, delete, update, replace
181181 $ this ->is_insert = false ;
182- if (\preg_match ("/^(insert|delete|update|replace)\s+/i " , $ query )) {
183- $ this ->is_insert = true ;
184- $ this ->_affectedRows = @\sqlsrv_rows_affected ($ this ->result );
185-
186- // Take note of the insert_id
187- if (\preg_match ("/^(insert|replace)\s+/i " , $ query )) {
188- $ identityResultset = @\sqlsrv_query ($ this ->dbh , "select SCOPE_IDENTITY() " );
189-
190- if ($ identityResultset != false ) {
191- $ identityRow = @\sqlsrv_fetch ($ identityResultset );
192- $ this ->insert_id = $ identityRow [0 ];
182+ try {
183+ if (\preg_match ("/^(insert|delete|update|replace)\s+/i " , $ query )) {
184+ $ this ->is_insert = true ;
185+ $ this ->_affectedRows = @\sqlsrv_rows_affected ($ this ->result );
186+
187+ // Take note of the insert_id
188+ if (\preg_match ("/^(insert|replace)\s+/i " , $ query )) {
189+ $ identityResultset = @\sqlsrv_query ($ this ->dbh , "select SCOPE_IDENTITY() " );
190+
191+ if ($ identityResultset != false ) {
192+ $ identityRow = @\sqlsrv_fetch ($ identityResultset );
193+ $ this ->insert_id = $ identityRow [0 ];
194+ }
193195 }
194- }
195- // Return number of rows affected
196- $ this ->return_val = $ this ->_affectedRows ;
197- } else { // Query was a select
198- // Take note of column info
199- $ i = 0 ;
200- foreach (@\sqlsrv_field_metadata ($ this ->result ) as $ field ) {
201- $ col = [];
202- foreach ($ field as $ name => $ value ) {
203- $ name = \strtolower ($ name );
204- if ($ name == "size " ) {
205- $ name = "max_length " ;
206- } elseif ($ name == "type " ) {
207- $ name = "typeid " ;
196+ // Return number of rows affected
197+ $ this ->return_val = $ this ->_affectedRows ;
198+ } else { // Query was a select
199+ // Take note of column info
200+ $ i = 0 ;
201+ foreach (@\sqlsrv_field_metadata ($ this ->result ) as $ field ) {
202+ $ col = [];
203+ foreach ($ field as $ name => $ value ) {
204+ $ name = \strtolower ($ name );
205+ if ($ name == "size " ) {
206+ $ name = "max_length " ;
207+ } elseif ($ name == "type " ) {
208+ $ name = "typeid " ;
209+ }
210+
211+ //DEFINED FOR E_STRICT
212+ $ col = new \stdClass ();
213+ $ col ->{$ name } = $ value ;
208214 }
209215
210- //DEFINED FOR E_STRICT
211- $ col = new \ stdClass () ;
212- $ col->{ $ name } = $ value ;
216+ $ col -> type = $ this -> get_datatype ( $ col );
217+ $ this -> col_info [ $ i ++] = $ col ;
218+ unset( $ col) ;
213219 }
214220
215- $ col ->type = $ this ->get_datatype ($ col );
216- $ this ->col_info [$ i ++] = $ col ;
217- unset($ col );
218- }
219-
220- // Store Query Results
221- $ num_rows = 0 ;
221+ // Store Query Results
222+ $ num_rows = 0 ;
222223
223- while ($ row = @\sqlsrv_fetch_object ($ this ->result )) {
224+ while ($ row = @\sqlsrv_fetch_object ($ this ->result )) {
224225
225- // Store results as an objects within main array
226- $ this ->last_result [$ num_rows ] = $ row ;
227- $ num_rows ++;
228- }
226+ // Store results as an objects within main array
227+ $ this ->last_result [$ num_rows ] = $ row ;
228+ $ num_rows ++;
229+ }
229230
230- @\sqlsrv_free_stmt ($ this ->result );
231+ @\sqlsrv_free_stmt ($ this ->result );
231232
232- // Log number of rows the query returned
233- $ this ->num_rows = $ num_rows ;
233+ // Log number of rows the query returned
234+ $ this ->num_rows = $ num_rows ;
234235
235- // Return number of rows selected
236- $ this ->return_val = $ this ->num_rows ;
236+ // Return number of rows selected
237+ $ this ->return_val = $ this ->num_rows ;
238+ }
239+ } catch (\Throwable $ ex ) {
240+ return false ;
237241 }
238242
239243 return $ this ->return_val ;
0 commit comments