}
function pdo_type() {
+ if (func_get_args()>0 and func_get_arg(0) === null) return PDO::PARAM_NULL;
if ($this->numeric) return PDO::PARAM_INT;
if (strpos($this->type,'bool') !== false ) return PDO::PARAM_BOOL;
if (strpos($this->type,'blob') !== false ) return PDO::PARAM_LOB; # not a bug LOB
return PDO::PARAM_STR;
}
- function bindParam($sth,$value) {
+ function bindParam($sth,$value,$name=null) {
# See: http://php.net/manual/en/pdostatement.bindparam.php
- $sth->bindParam(':'.$this->name, $value, PDO::PARAM_INT);
- $sth->bindParam(':'.$this->name, $value, PDO::PARAM_STR);
- $sth->bindParam(':calories', $calories, PDO::PARAM_INT);
+ if ($name === null) $name = ':'.$this->name;
+#debug($this->name . " | $name | $value | $this->type | " . $this->size()."<br/>");
+ return $sth->bindParam($name, $value, $this->pdo_type($value), $this->size());
+// NB 27.07.15 return $sth->bindParam($name, $value, $this->pdo_type($value));
}
}
function url_list($k='',$v='') {
$params = array();
+ $fields = ($this->db->p('action') == 'delete') ? array() : $this->fields();
- foreach (array_merge( $this->params, array_keys($this->fields()) ) as $f) {
+ foreach (array_merge( $this->params, array_keys($fields) ) as $f) {
if (@strcmp($this->db->p($f),'')==0) continue;
$params[$f] = $this->db->p($f);
}
function insert($hvalues) {
- $names = $values = array();
- #var_dump($hvalues);
+ $fields = $values = array();
+#var_dump($hvalues);
foreach ($this->fields() as $name => $field) {
if (!isset($hvalues[$name])) continue;
if ($field->key and $field->autoincrement()) continue;
- $names[] = $field->sql_name();
- #$values[] = $field->quote($hvalues[$name]);
+ $fields[$field->sql_name()] = $field;
$values[] = $hvalues[$name];
}
#bye($values);
$sql =
- 'INSERT INTO '. $this->sql_name() . ' (' . join(',',$names).')'
+ 'INSERT INTO '. $this->sql_name() . ' (' . join(',',array_keys($fields)).')'
#.' VALUES (' . join(',',$values).')'
- .' VALUES (' . join(',',ar_map('"?"',$values)) . ')'
+ .' VALUES (' . join(',',ar_map('":$a"',array_keys($fields))) . ')'
;
- bye(array($sql,$values));
+
+ if (!($query = $this->db->conn->prepare($sql))) {
+ err('PDO::errorInfo(): ' .join(' ', $this->db->conn->errorInfo()) .PHP_EOL);
+ return false;
+ }
+
+ foreach ($fields as $name => $field) $field->bindParam($query,$hvalues[$name],":$name");
+
+#debug(array($sql,$values));
+ if (!($execute = $query->execute())) {
+ err('PDO::errorInfo(): ' .join(' ', $this->db->conn->errorInfo()) .PHP_EOL);
+ return false;
+ }
+
+ return $execute;
return $this->db->exec($sql,$values);
return $this->db->exec($sql);
}
foreach ($fields as $name) {
- $query->bindParam(":$name", $hvalues[$name]);
+ $field->bindParam($query,$hvalues[$name],":$name");
}
foreach ($keys as $name) {
- $query->bindParam(":key_$name", $hvalues[$name]);
+ $field->bindParam($query,$hvalues[$name],":key_$name");
}
#return $sql;
+ #bye($sql);
if (!($execute = $query->execute())) {
err('PDO::errorInfo(): ' .join(' ', $this->db->conn->errorInfo()) .PHP_EOL);
return false;