Skip to content

Commit d910245

Browse files
committed
fixes for php 8
1 parent 86c0e0e commit d910245

File tree

4 files changed

+68
-64
lines changed

4 files changed

+68
-64
lines changed

lib/Database/ez_sqlsrv.php

Lines changed: 49 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -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;

tests/pdo/pdo_pgsqlTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -195,22 +195,22 @@ public function testSelecting()
195195
public function testWhereGrouping()
196196
{
197197
$this->assertTrue($this->object->connect('pgsql:host=' . self::TEST_DB_HOST . ';dbname=' . self::TEST_DB_NAME . ';port=' . self::TEST_DB_PORT, self::TEST_DB_USER, self::TEST_DB_PASSWORD));
198-
$this->object->drop('unit_test');
199-
$this->object->query('CREATE TABLE unit_test(id integer, test_key varchar(50), active tinyint(1), PRIMARY KEY (ID))');
200-
$this->object->insert('unit_test', array('id' => '1', 'test_key' => 'testing 1', 'active' => 1));
201-
$this->object->insert('unit_test', array('id' => '2', 'test_key' => 'testing 2', 'active' => 0));
202-
$this->object->insert('unit_test', array('id' => '3', 'test_key' => 'testing 3', 'active' => 1));
203-
$this->object->insert('unit_test', array('id' => '4', 'test_key' => 'testing 4', 'active' => 1));
204-
205-
$result = $this->object->selecting('unit_test', '*', where(eq('active', '1'), grouping(like('test_key', '%1%', _OR), like('test_key', '%3%'))));
198+
$this->object->drop('unit_test_more');
199+
$this->object->query('CREATE TABLE unit_test_more(id integer, test_key varchar(50), active_data tinyint(1), PRIMARY KEY (ID))');
200+
$this->object->insert('unit_test_more', array('id' => '1', 'test_key' => 'testing 1', 'active_data' => 1));
201+
$this->object->insert('unit_test_more', array('id' => '2', 'test_key' => 'testing 2', 'active_data' => 0));
202+
$this->object->insert('unit_test_more', array('id' => '3', 'test_key' => 'testing 3', 'active_data' => 1));
203+
$this->object->insert('unit_test_more', array('id' => '4', 'test_key' => 'testing 4', 'active_data' => 1));
204+
205+
$result = $this->object->selecting('unit_test_more', '*', where(eq('active_data', 1), grouping(like('test_key', '%1%', _OR), like('test_key', '%3%'))));
206206
$i = 1;
207207
foreach ($result as $row) {
208208
$this->assertEquals($i, $row->id);
209209
$this->assertEquals('testing ' . $i, $row->test_key);
210210
$i = $i + 2;
211211
}
212212

213-
$this->object->drop('unit_test');
213+
$this->object->drop('unit_test_more');
214214
}
215215

216216
public function testJoins()

tests/pdo/pdo_sqlsrvTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -199,21 +199,21 @@ public function testSelecting()
199199
public function testWhereGrouping()
200200
{
201201
$this->assertTrue($this->object->connect('sqlsrv:Server=' . self::TEST_DB_HOST . ';Database=' . self::TEST_DB_NAME, self::TEST_DB_USER, self::TEST_DB_PASSWORD));
202-
$this->object->query('CREATE TABLE unit_test(id integer, test_key varchar(50), active_data tinyint(1), PRIMARY KEY (ID))');
203-
$this->object->insert('unit_test', array('id' => 1, 'test_key' => 'testing 1', 'active_data' => 1));
204-
$this->object->insert('unit_test', array('id' => 2, 'test_key' => 'testing 2', 'active_data' => 0));
205-
$this->object->insert('unit_test', array('id' => 3, 'test_key' => 'testing 3', 'active_data' => 1));
206-
$this->object->insert('unit_test', array('id' => 4, 'test_key' => 'testing 4', 'active_data' => 1));
202+
$this->object->query('CREATE TABLE unit_test_other(id integer, test_key varchar(50), active_data tinyint(1), PRIMARY KEY (ID))');
203+
$this->object->insert('unit_test_other', array('id' => 1, 'test_key' => 'testing 1', 'active_data' => 1));
204+
$this->object->insert('unit_test_other', array('id' => 2, 'test_key' => 'testing 2', 'active_data' => 0));
205+
$this->object->insert('unit_test_other', array('id' => 3, 'test_key' => 'testing 3', 'active_data' => 1));
206+
$this->object->insert('unit_test_other', array('id' => 4, 'test_key' => 'testing 4', 'active_data' => 1));
207207

208-
$result = $this->object->selecting('unit_test', '*', where(eq('active_data', '1'), grouping(like('test_key', '%1%', _OR), like('test_key', '%3%'))));
208+
$result = $this->object->selecting('unit_test_other', '*', where(eq('active_data', '1'), grouping(like('test_key', '%1%', _OR), like('test_key', '%3%'))));
209209
$i = 1;
210210
foreach ($result as $row) {
211211
$this->assertEquals($i, $row->id);
212212
$this->assertEquals('testing ' . $i, $row->test_key);
213213
$i = $i + 2;
214214
}
215215

216-
$this->object->drop('unit_test');
216+
$this->object->drop('unit_test_other');
217217
}
218218

219219
public function testJoins()

tests/sqlsrv/sqlsrvTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,9 +363,9 @@ public function testQuery_prepared()
363363
column('prepare_key', VARCHAR, 50)
364364
);
365365

366-
$this->object->insert('prepare_test', ['id' => 1, 'prepare_key' => 'test 2']);
367-
$this->object->query_prepared('INSERT INTO prepare_test( id, prepare_key ) VALUES( ?, ? )', [4, 'test 10']);
368-
$this->object->query_prepared('INSERT INTO prepare_test( id, prepare_key ) VALUES( ?, ? )', [9, 'test 3']);
366+
$this->object->query_prepared('INSERT INTO prepare_test(id, prepare_key ) VALUES( ?, ? )', [1, 'test 2']);
367+
$this->object->query_prepared('INSERT INTO prepare_test(id, prepare_key ) VALUES( ?, ? )', [4, 'test 10']);
368+
$this->object->query_prepared('INSERT INTO prepare_test(id, prepare_key ) VALUES( ?, ? )', [9, 'test 3']);
369369

370370
$this->object->query_prepared('SELECT id, prepare_key FROM prepare_test WHERE id = ?', [9]);
371371
$query = $this->object->queryResult();

0 commit comments

Comments
 (0)