/** * queries data from the db if its not cached in dbData * @param string $table * @param string $pk * @param int $pkval * * @return array !REFRENCE! */ public static function &getRowData($table, $pk, $pkval) { $rowRef = dbData::rowRefrence($table, $pk, $pkval); if (!$rowRef) { $rowRef = db::q1rAssoc("select * from {$table} where {$pk}='" . db::sqlEsc($pkval) . "'"); } return $rowRef; }
/** * this method performs both insert and update * this only runs a query if data has changed * this updates dbData through the orig refrence * saving behavior is determined by the contents of the orig array * if empty orig insert else update * after a save all objects that refrence this orig data will be refcrenced to the new data * * @return bool or int affected rows */ public function save() { $res = true; $changedData = $this->changedData(); if (count($changedData)) { if (!empty($this->orig)) { $res = dbHelper::updateQry($this->tableName, $changedData, array($this->primaryKey => $this->data[$this->primaryKey])) ? true : false; $this->orig = $this->data; } else { //if this row has been deleted but someone else saves data to it this will automatically restore the row from $data $res = dbHelper::insertQry($this->tableName, $this->data) ? true : false; $this->data[$this->primaryKey] = db::insertID(); dbData::addRow($this->tableName, $this->primaryKey, $this->data); $this->orig =& dbData::rowRefrence($this->tableName, $this->primaryKey, $this->data[$this->primaryKey]); } } return $res; }