/** * 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; }
/** * delete all rows from this table matching where clause * @param array $where * @see dbHelper::joinWhere() for $where formatting * @param mixed $andor * @see dbHelper::andOr() for more info on $setor formatting * @param string $bypasswhere this is a flag to prevent delete all if you pass an empty $where array * @see dbHelper::deleteQry() for more info * * @return bool or int (affected rows) */ public function deleteRowsWhere($where, $andor = 'AND', $bypassWhere = 'DONT_DELETE_EVERYTHING') { $ret = dbHelper::deleteQry($this->tableName, $where, $andor, $bypassWhere); if ($ret) { dbData::emptyTable($this->tableName); } return $ret; }
/** * this is to remove all data from this obejct * @return true */ public static function emptyData() { self::$data = array(); return true; }
// PHPQuery examples :) // you can write this code in the way you want, it is very flexible // first define DEVELOPER MODE, if the constant get value true, the framework show errors and remake the cache of tpl always. // if the constant get value false, the framework DON'T SHOW ERRORS, and don't remake cache of tpls (only if there are not or you delete old cache) define('DEVMODE', true); // this is obsolete after version 1.0.1 // converted in _::declare_component('searcher'); define('REQUIRE_SEARCHER', true); // now, require the core of PHPQuery, this is only line necessary require 'phpquery/core.php'; // this set new values for the default configuration of DB // see default config in phpquery/default_config/dbData.php dbData::$host = 'localhost'; dbData::$user = '******'; dbData::$pass = ''; dbData::$db = 'adminwp'; // if you don't like .tpl extension in views, you set do you want // you see default config in phpquery/default_config/tplData.php //tplData::$extension = '.html'; // initialize the framework using debug mode (you can change the constant if like) _::init(DEVMODE); // the important, you need declare the controllers that exist // first declare file (example.php), later you declare the controllers in the file _::declare_controller('example', 'example', 'example_2', 'example_3', 'example_4'); // en general.php el controlador home _::declare_controller('real_example', 'home', 'login', 'login2', 'registro', 'registro2'); // if you like add others definitions and declarations in external file // you can require or include others files and declare it require 'others/headers.php'; // REQUERIMOS TODAS LAS FUNCIONES QUE SE EJECUTARAN EN EL FOOTER require 'others/footer.php';