/** * Inserts into a table * * @param string $table table to insert into * @param string $query query to use to insert * * @return bool|void */ public function insert($table, $query) { $this->db->connect(); $table = $this->db->prefix($table); $query = 'INSERT INTO ' . $table . ' ' . $query; if (!$this->db->queryF($query)) { if (!isset($this->f_tables['insert'][$table])) { $this->f_tables['insert'][$table] = 1; } else { $this->f_tables['insert'][$table]++; } return false; } else { if (!isset($this->s_tables['insert'][$table])) { $this->s_tables['insert'][$table] = 1; } else { $this->s_tables['insert'][$table]++; } return $this->db->getInsertId(); } }
/** * @param object $obj * @param bool $force * * @return bool|void */ public function insert(&$obj, $force = false) { // Make sure object is of correct type if (strcasecmp($this->classname, get_class($obj)) != 0) { return false; } // Make sure object needs to be stored in DB if (!$obj->isDirty()) { return true; } // Make sure object fields are filled with valid values if (!$obj->cleanVars()) { return false; } // Create query for DB update if ($obj->isNew()) { // Determine next auto-gen ID for table $this->_db->genId($this->_db->prefix($this->_dbtable) . '_uid_seq'); $sql = $this->_insertQuery($obj); } else { $sql = $this->_updateQuery($obj); } // Update DB if (false != $force) { $result = $this->_db->queryF($sql); } else { $result = $this->_db->query($sql); } if (!$result) { $obj->setErrors('The query returned an error. ' . $this->db->error()); return false; } //Make sure auto-gen ID is stored correctly in object if ($obj->isNew()) { $obj->assignVar($this->_idfield, $this->_db->getInsertId()); } return true; }