foreach ($data as $key => $value) {
if(is_int($value))
$param = PDO::PARAM_INT;
+ elseif(is_float($value))
+ $param = PDO::PARAM_STR;
elseif(is_bool($value))
$param = PDO::PARAM_BOOL;
elseif(is_null($value))
public function insertInto($table, $data)
{
- if (!is_array($data)) throw Exception('insertInto called without data array');
+ if (!is_array($data)) throw new Exception('insertInto called without data array');
$columns = array();
foreach ($data as $k => $v) {
$columns[] = $k;
- $values[] = ':' . $k;
+ if (strtolower($v) == 'now()' || strtolower($v) == 'current_timestamp') {
+ $values[] = 'now()';
+ unset($data[$k]);
+ } else
+ $values[] = ':' . $k;
}
$sql = sprintf("INSERT INTO %s (%s) VALUES (%s)",
public function update($table, $data, $condition)
{
- if (!is_array($data)) throw Exception('update called without data array');
- if (empty($condition)) throw Exception('update called without condition');
+ if (!is_array($data)) throw new Exception('update called without data array');
+ if (empty($condition)) throw new Exception('update called without condition');
$set = array();
- foreach ($data as $k => $v)
- $set[] = $k.'=:'.$k;
+ foreach ($data as $k => $v) {
+ if (strtolower($v) == 'now()' || strtolower($v) == 'current_timestamp') {
+ $set[] = $k.'=now()';
+ unset($data[$k]);
+ } else
+ $set[] = $k.'=:'.$k;
+ }
$sql = sprintf("UPDATE %s SET %s WHERE %s",
$table,