From d7d332f373714f1d97feed5f510b57fb51c45e81 Mon Sep 17 00:00:00 2001 From: Oliver Bayes-Shelton Date: Tue, 30 Oct 2012 15:05:49 +0000 Subject: [PATCH] Updated the MysqliDb.php file to work with php 5.3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updated the MysqliDb.php file to work with php 5.3+ be removing call by reference and adding a refValues method. --- MysqliDb.php | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/MysqliDb.php b/MysqliDb.php index 30646925..c8a77d33 100644 --- a/MysqliDb.php +++ b/MysqliDb.php @@ -105,10 +105,11 @@ public function rawQuery($query, $bindParams = NULL) $params = array(''); // Create the empty 0 index foreach ($bindParams as $prop => $val) { $params[0] .= $this->_determineType($val); - array_push($params, &$bindParams[$prop]); + array_push($params, $bindParams[$prop]); } - call_user_func_array(array($stmt, 'bind_param'), $params); + call_user_func_array(array($stmt, "bind_param"),$this->refValues($params)); + } $stmt->execute(); @@ -343,7 +344,7 @@ protected function _buildQuery($numRows = NULL, $tableData = NULL) if ($hasTableData) { $this->_bindParams[0] = $this->_paramTypeList; foreach ($tableData as $prop => $val) { - array_push($this->_bindParams, &$tableData[$prop]); + array_push($this->_bindParams, $tableData[$prop]); } } // Prepare where condition bind parameters @@ -351,13 +352,13 @@ protected function _buildQuery($numRows = NULL, $tableData = NULL) if ($this->_where) { $this->_bindParams[0] .= $this->_whereTypeList; foreach ($this->_where as $prop => $val) { - array_push($this->_bindParams, &$this->_where[$prop]); + array_push($this->_bindParams, $this->_where[$prop]); } } } // Bind parameters to statment if ($hasTableData || $hasConditional){ - call_user_func_array(array($stmt, 'bind_param'), $this->_bindParams); + call_user_func_array(array($stmt, "bind_param"),$this->refValues($this->_bindParams)); } return $stmt; @@ -378,10 +379,10 @@ protected function _dynamicBindResults($stmt) $meta = $stmt->result_metadata(); while ($field = $meta->fetch_field()) { - array_push($parameters, &$row[$field->name]); + array_push($parameters, $row[$field->name]); } - call_user_func_array(array($stmt, 'bind_result'), $parameters); + call_user_func_array(array($stmt, "bind_result"),$this->refValues($parameters)); while ($stmt->fetch()) { $x = array(); @@ -410,4 +411,16 @@ public function __destruct() $this->_mysqli->close(); } + function refValues($arr) + { + //Reference is required for PHP 5.3+ + if (strnatcmp(phpversion(),'5.3') >= 0) { + $refs = array(); + foreach($arr as $key => $value) + $refs[$key] = &$arr[$key]; + return $refs; + } + return $arr; + } + } // END class \ No newline at end of file