Skip to content

Commit ac3330d

Browse files
committed
Merge pull request #3 from obayesshelton/master
Updated the MysqliDb.php file to work with php 5.3+
2 parents 12e6984 + d7d332f commit ac3330d

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

MysqliDb.php

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,11 @@ public function rawQuery($query, $bindParams = NULL)
105105
$params = array(''); // Create the empty 0 index
106106
foreach ($bindParams as $prop => $val) {
107107
$params[0] .= $this->_determineType($val);
108-
array_push($params, &$bindParams[$prop]);
108+
array_push($params, $bindParams[$prop]);
109109
}
110110

111-
call_user_func_array(array($stmt, 'bind_param'), $params);
111+
call_user_func_array(array($stmt, "bind_param"),$this->refValues($params));
112+
112113
}
113114

114115
$stmt->execute();
@@ -354,21 +355,21 @@ protected function _buildQuery($numRows = NULL, $tableData = NULL)
354355
if ($hasTableData) {
355356
$this->_bindParams[0] = $this->_paramTypeList;
356357
foreach ($tableData as $prop => $val) {
357-
array_push($this->_bindParams, &$tableData[$prop]);
358+
array_push($this->_bindParams, $tableData[$prop]);
358359
}
359360
}
360361
// Prepare where condition bind parameters
361362
if($hasConditional) {
362363
if ($this->_where) {
363364
$this->_bindParams[0] .= $this->_whereTypeList;
364365
foreach ($this->_where as $prop => $val) {
365-
array_push($this->_bindParams, &$this->_where[$prop]);
366+
array_push($this->_bindParams, $this->_where[$prop]);
366367
}
367368
}
368369
}
369370
// Bind parameters to statment
370371
if ($hasTableData || $hasConditional){
371-
call_user_func_array(array($stmt, 'bind_param'), $this->_bindParams);
372+
call_user_func_array(array($stmt, "bind_param"),$this->refValues($this->_bindParams));
372373
}
373374

374375
return $stmt;
@@ -389,10 +390,10 @@ protected function _dynamicBindResults($stmt)
389390
$meta = $stmt->result_metadata();
390391

391392
while ($field = $meta->fetch_field()) {
392-
array_push($parameters, &$row[$field->name]);
393+
array_push($parameters, $row[$field->name]);
393394
}
394395

395-
call_user_func_array(array($stmt, 'bind_result'), $parameters);
396+
call_user_func_array(array($stmt, "bind_result"),$this->refValues($parameters));
396397

397398
while ($stmt->fetch()) {
398399
$x = array();
@@ -421,4 +422,16 @@ public function __destruct()
421422
$this->_mysqli->close();
422423
}
423424

425+
function refValues($arr)
426+
{
427+
//Reference is required for PHP 5.3+
428+
if (strnatcmp(phpversion(),'5.3') >= 0) {
429+
$refs = array();
430+
foreach($arr as $key => $value)
431+
$refs[$key] = &$arr[$key];
432+
return $refs;
433+
}
434+
return $arr;
435+
}
436+
424437
} // END class

0 commit comments

Comments
 (0)