Commit 44263146 authored by Alexander Butenko's avatar Alexander Butenko

Streamline variable bindings

parent b1d87156
...@@ -48,12 +48,6 @@ class MysqliDb ...@@ -48,12 +48,6 @@ class MysqliDb
* @var array * @var array
*/ */
protected $_where = array(); protected $_where = array();
/**
* Dynamic type list for where condition values
*
* @var array
*/
protected $_whereTypeList;
/** /**
* Dynamic type list for order by condition value * Dynamic type list for order by condition value
*/ */
...@@ -62,12 +56,6 @@ class MysqliDb ...@@ -62,12 +56,6 @@ class MysqliDb
* Dynamic type list for group by condition value * Dynamic type list for group by condition value
*/ */
protected $_groupBy = array(); protected $_groupBy = array();
/**
* Dynamic type list for table data values
*
* @var array
*/
protected $_paramTypeList;
/** /**
* Dynamic array that holds a combination of where condition/table data value types and parameter referances * Dynamic array that holds a combination of where condition/table data value types and parameter referances
* *
...@@ -133,8 +121,6 @@ class MysqliDb ...@@ -133,8 +121,6 @@ class MysqliDb
$this->_groupBy = array(); $this->_groupBy = array();
$this->_bindParams = array(''); // Create the empty 0 index $this->_bindParams = array(''); // Create the empty 0 index
$this->_query = null; $this->_query = null;
$this->_whereTypeList = null;
$this->_paramTypeList = null;
$this->count = 0; $this->count = 0;
} }
...@@ -472,7 +458,8 @@ class MysqliDb ...@@ -472,7 +458,8 @@ class MysqliDb
$this->_query .= $column." = "; $this->_query .= $column." = ";
if (!is_array ($value)) { if (!is_array ($value)) {
$this->_paramTypeList .= $this->_determineType($value); $this->_bindParams[0] .= $this->_determineType($value);
array_push ($this->_bindParams, $value);
$this->_query .= '?, '; $this->_query .= '?, ';
} else { } else {
$key = key ($value); $key = key ($value);
...@@ -484,8 +471,10 @@ class MysqliDb ...@@ -484,8 +471,10 @@ class MysqliDb
case '[F]': case '[F]':
$this->_query .= $val[0] . ", "; $this->_query .= $val[0] . ", ";
if (!empty ($val[1])) { if (!empty ($val[1])) {
foreach ($val[1] as $v) foreach ($val[1] as $v) {
$this->_paramTypeList .= $this->_determineType($v); $this->_bindParams[0] .= $this->_determineType($v);
array_push ($this->_bindParams, $v);
}
} }
break; break;
default: default:
...@@ -519,24 +508,29 @@ class MysqliDb ...@@ -519,24 +508,29 @@ class MysqliDb
$comparison = ' IN ('; $comparison = ' IN (';
foreach($val as $v){ foreach($val as $v){
$comparison .= ' ?,'; $comparison .= ' ?,';
$this->_whereTypeList .= $this->_determineType( $v ); $this->_bindParams[0] .= $this->_determineType( $v );
array_push ($this->_bindParams, $v);
} }
$comparison = rtrim($comparison, ',').' ) '; $comparison = rtrim($comparison, ',').' ) ';
break; break;
case 'between': case 'between':
$comparison = ' BETWEEN ? AND ? '; $comparison = ' BETWEEN ? AND ? ';
$this->_whereTypeList .= $this->_determineType( $val[0] ); $this->_bindParams[0] .= $this->_determineType( $val[0] );
$this->_whereTypeList .= $this->_determineType( $val[1] ); $this->_bindParams[0] .= $this->_determineType( $val[1] );
array_push ($this->_bindParams, $val[0]);
array_push ($this->_bindParams, $val[1]);
break; break;
default: default:
// We are using a comparison operator with only one parameter after it // We are using a comparison operator with only one parameter after it
$comparison = ' '.$key.' ? '; $comparison = ' '.$key.' ? ';
// Determines what data type the where column is, for binding purposes. // Determines what data type the where column is, for binding purposes.
$this->_whereTypeList .= $this->_determineType( $val ); $this->_bindParams[0] .= $this->_determineType( $val );
array_push ($this->_bindParams, $val);
} }
} else { } else {
// Determines what data type the where column is, for binding purposes. // Determines what data type the where column is, for binding purposes.
$this->_whereTypeList .= $this->_determineType($value); $this->_bindParams[0] .= $this->_determineType($value);
array_push ($this->_bindParams, $value);
} }
// Prepares the reset of the SQL query. // Prepares the reset of the SQL query.
$this->_query .= ($andOr.$column.$comparison); $this->_query .= ($andOr.$column.$comparison);
...@@ -574,34 +568,6 @@ class MysqliDb ...@@ -574,34 +568,6 @@ class MysqliDb
// Prepare query // Prepare query
$stmt = $this->_prepareQuery(); $stmt = $this->_prepareQuery();
// Prepare table data bind parameters
if ($hasTableData) {
$this->_bindParams[0] = $this->_paramTypeList;
foreach ($tableData as $val) {
if (!is_array ($val)) {
array_push ($this->_bindParams, $val);
} else if (!empty($val['[F]'][1]) && is_array ($val['[F]'][1])) {
// collect func() arguments
foreach ($val['[F]'][1] as $val)
array_push($this->_bindParams, $val);
}
}
}
// Prepare where condition bind parameters
if ($hasConditional) {
if ($this->_where) {
$this->_bindParams[0] .= $this->_whereTypeList;
foreach ($this->_where as $val) {
$val = $val[1];
if (!is_array ($val)) {
array_push ($this->_bindParams, $val);
} else {
foreach ($val as $v)
array_push ($this->_bindParams, $v);
}
}
}
}
// Bind parameters to statment // Bind parameters to statment
if ($hasTableData || $hasConditional) { if ($hasTableData || $hasConditional) {
call_user_func_array(array($stmt, 'bind_param'), $this->refValues($this->_bindParams)); call_user_func_array(array($stmt, 'bind_param'), $this->refValues($this->_bindParams));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment