public static function insertIfNotFound($table, $col, $text) { $topicTable = new OptionList(array('name' => $table)); $select = $topicTable->select()->from($table, 'id')->where("{$col} = ?", $text); $row = $topicTable->fetchRow($select); if ($row) { return $row->id; } return $topicTable->insert(array($col => $text)); }
public function dbAction() { set_time_limit(300); require_once 'Zend/Db.php'; //set a default database adaptor //$db = Zend_Db::factory ( 'PDO_SQLITE', array ('dbname' => Globals::$BASE_PATH . 'app/desktop/trainsmart.active.sqlite' ) ); $db = Zend_Db::factory('PDO_SQLITE', array('dbname' => $this->package_dir . '/data/trainsmart.active.sqlite')); $GLOBALS['debug'] = $this->package_dir . '/data/trainsmart.active.sqlite'; require_once 'Zend/Db/Adapter/Abstract.php'; if (!$db instanceof Zend_Db_Adapter_Abstract) { require_once 'Zend/Db/Table/Exception.php'; throw new Zend_Db_Table_Exception('Could not create sqlite adaptor'); } $this->desktop_db = $db; $litedb = $this->desktop_db; //$liteSysTable = new System(array( Zend_Db_Table_Abstract::ADAPTER => $litedb)); //$liteSysTable->select('*'); require_once 'sync/SyncCompare.php'; $option_tables = SyncCompare::$compareTypes; // require_once('models/table/System.php'); foreach ($option_tables as $opt) { //$GLOBALS['debug'] = $opt; $optTable = new OptionList(array('name' => $opt)); $liteTable = new OptionList(array('name' => $opt, Zend_Db_Table_Abstract::ADAPTER => $litedb)); $optTable->select('*'); $rowset = $optTable->fetchAll(); $liteKeys = $liteTable->createRow()->toArray(); foreach ($rowset as $optRow) { $data = $optRow->toArray(); foreach (array_keys($data) as $k) { if (!array_key_exists($k, $liteKeys)) { unset($data[$k]); } } $liteTable->insert($data); } } /* $sysTable = new System(); $sysTable->select('*'); $row = $sysTable->fetchRow(); $liteSysTable->insert($row->toArray()); */ }