Skip to content

Updated the MysqliDb.php file to work with php 5.3+ #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 30, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions MysqliDb.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -343,21 +344,21 @@ 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
if($hasConditional) {
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;
Expand All @@ -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();
Expand Down Expand Up @@ -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