function insertObject( $table, &$object, $keyName = NULL ) {
$fmtsql = 'INSERT INTO '.$this->nameQuote($table).' (%s)VALUES(%s)'; //I am not sure how these values are obtained to do an insert
$fields = array();
foreach (get_object_vars( $object ) as $k => $v) {
if (is_array($v) or is_object($v) or $v === NULL) {
continue;
}
if ($k[0] == '_') { // internal field
continue;
}
$fields[] = $this->nameQuote( $k );
$values[] = $this->isQuoted( $k ) ? $this->Quote( $v ) : (int) $v;
}
$this->setQuery( sprintf( $fmtsql, implode( ",", $fields ) , implode( ",", $values ) ) );
if (!$this->query()) {
return false;
}
$id = $this->insertid();
if ($keyName && $id) {
$object->$keyName = $id;
}
return true;
}
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
From novice to tech pro — start learning today.