Commit 1d874621 authored by Alexander Butenko's avatar Alexander Butenko

Allow to pass bind variables for func()

parent 0e8865e0
...@@ -433,8 +433,14 @@ class MysqliDb ...@@ -433,8 +433,14 @@ class MysqliDb
$this->_query .= $prop ." = "; $this->_query .= $prop ." = ";
if (!empty($value['[I]'])) if (!empty($value['[I]']))
$this->_query .= $prop . $value['[I]'] . ", "; $this->_query .= $prop . $value['[I]'] . ", ";
else else {
$this->_query .= $value['[F]'] . ", "; $this->_query .= $value['[F]'][0] . ", ";
if (is_array ($value['[F]'][1])) {
foreach ($value['[F]'][1] as $key => $val) {
$this->_paramTypeList .= $this->_determineType($val);
}
}
}
} else { } else {
// determines what data type the item is, for binding purposes. // determines what data type the item is, for binding purposes.
$this->_paramTypeList .= $this->_determineType($value); $this->_paramTypeList .= $this->_determineType($value);
...@@ -521,8 +527,14 @@ class MysqliDb ...@@ -521,8 +527,14 @@ class MysqliDb
if (is_array($val)) { if (is_array($val)) {
if (!empty($val['[I]'])) if (!empty($val['[I]']))
$this->_query .= $keys[$key].$val['[I]'].", "; $this->_query .= $keys[$key].$val['[I]'].", ";
else else {
$this->_query .= $val['[F]'].", "; $this->_query .= $val['[F]'][0].", ";
if (is_array ($val['[F]'][1])) {
foreach ($val['[F]'][1] as $key => $value) {
$this->_paramTypeList .= $this->_determineType($value);
}
}
}
continue; continue;
} }
...@@ -550,8 +562,15 @@ class MysqliDb ...@@ -550,8 +562,15 @@ class MysqliDb
if ($hasTableData) { if ($hasTableData) {
$this->_bindParams[0] = $this->_paramTypeList; $this->_bindParams[0] = $this->_paramTypeList;
foreach ($tableData as $prop => $val) { foreach ($tableData as $prop => $val) {
if (!is_array($tableData[$prop])) if (!is_array($tableData[$prop])) {
array_push($this->_bindParams, $tableData[$prop]); array_push($this->_bindParams, $tableData[$prop]);
continue;
}
if (is_array($tableData[$prop]['[F]'][1])) {
foreach ($tableData[$prop]['[F]'][1] as $val)
array_push($this->_bindParams, $val);
}
} }
} }
// Prepare where condition bind parameters // Prepare where condition bind parameters
...@@ -717,7 +736,7 @@ class MysqliDb ...@@ -717,7 +736,7 @@ class MysqliDb
* @return array * @return array
*/ */
public function now ($diff = null, $func = "NOW()") { public function now ($diff = null, $func = "NOW()") {
return Array ("[F]" => $this->interval($diff, $func)); return Array ("[F]" => Array($this->interval($diff, $func)));
} }
/** /**
...@@ -740,8 +759,8 @@ class MysqliDb ...@@ -740,8 +759,8 @@ class MysqliDb
* Method generates user defined function call * Method generates user defined function call
* @param string user function body * @param string user function body
*/ */
public function func ($expr) { public function func ($expr, $bindParams = null) {
return Array ("[F]" => $expr); return Array ("[F]" => Array($expr, $bindParams));
} }
} // END class } // END class
...@@ -30,13 +30,13 @@ $data = Array( ...@@ -30,13 +30,13 @@ $data = Array(
'login' => 'admin', 'login' => 'admin',
'firstName' => 'John', 'firstName' => 'John',
'lastName' => 'Doe', 'lastName' => 'Doe',
'fullName' => $db->func('CONCAT(firstName," ",lastName)'), 'fullName' => $db->func('CONCAT(firstName,?,lastName)',Array (" ")),
// fullname = CONCAT(firstName,"",lastName) // fullname = CONCAT(firstName,"",lastName)
'createdAt' => $db->now(), 'createdAt' => $db->now(),
// createdAt = NOW() // createdAt = NOW()
'expires' => $db->now('+1Y') 'expires' => $db->now('+1Y')
// expires = NOW() + interval 1 year // expires = NOW() + interval 1 year
// Supported intervals [s]econd, [m]inute, [h]hour, [d]day, [M]onth, [Y]ear // Supported intervals [s]econd, [m]inute, [h]hour, [d]day, [M]onth, [Y]ear
); );
$id = $db->insert('users', $data) $id = $db->insert('users', $data)
...@@ -50,7 +50,7 @@ $data = Array ( ...@@ -50,7 +50,7 @@ $data = Array (
'firstName' => 'Bobby', 'firstName' => 'Bobby',
'lastName' => 'Tables', 'lastName' => 'Tables',
'editCount' => $db->inc(2) 'editCount' => $db->inc(2)
// editCount = editCount + 2; // editCount = editCount + 2;
); );
$db->where('id', 1); $db->where('id', 1);
if($db->update('users', $data)) echo 'successfully updated'; if($db->update('users', $data)) echo 'successfully updated';
......
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