function __construct($config, $options = [])
{
- $options += [ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION ];
+ $options += [
+ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
+ PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ,
+ ];
$this->dbh = new PDO($config, NULL, NULL, $options);
}
return $stmt;
}
+ function _value($val, &$params)
+ {
+ $params[] = $val;
+ return '?';
+ }
+
function insert($table, $row)
{
+ $params = [];
+ $cols = [];
+ foreach ($row as $col => $val) {
+ $cols[] = $this->_value($val, $params);
+ }
$sql = sprintf('INSERT INTO %s (%s) VALUES (%s)',
'"'.$table.'"',
implode(', ', array_keys($row)),
- implode(', ', array_fill(0, count($row), '?'))
+ implode(', ', $cols)
);
- return $this->query($sql, array_values($row));
+ return $this->query($sql, $params);
}
}