* @package convert * @version $Id$ * @link http://www.zentao.net */ ?> post->dbHost}; port={$this->post->dbPort};dbname={$this->post->dbName}"; try { $dbh = new PDO($dsn, $this->post->dbUser, $this->post->dbPassword); $dbh->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ); $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $dbh->exec("SET NAMES {$this->post->dbCharset}"); $this->sourceDBH = $dbh; return $dbh; } catch (PDOException $exception) { return $exception->getMessage(); } } /** * Check database exits or not. * * @access public * @return bool */ public function dbExists() { $sql = "SHOW DATABASES like '{$this->post->db->name}'"; return $this->dbh->query($sql)->fetch(); } /** * Check table exits or not. * * @access public * @return bool */ public function tableExists($table) { $sql = "SHOW tables like '$table'"; return $this->dbh->query($sql)->fetch(); } /** * Save the max id of every table. Thus when we convert again, when can delete id larger then the saved max id. * * @access public * @return void */ public function saveState() { /* Get user defined tables. */ $constants = get_defined_constants(true); $userConstants = $constants['user']; /* These tables needn't save. */ unset($userConstants['TABLE_BURN']); unset($userConstants['TABLE_GROUPPRIV']); unset($userConstants['TABLE_PROJECTPRODUCT']); unset($userConstants['TABLE_PROJECTSTORY']); unset($userConstants['TABLE_STORYSPEC']); unset($userConstants['TABLE_TEAM']); unset($userConstants['TABLE_USERGROUP']); /* Get max id of every table. */ foreach($userConstants as $key => $value) { if(strpos($key, 'TABLE') === false) continue; if($key == 'TABLE_COMPANY') continue; $state[$value] = (int)$this->dao->select('MAX(id) AS id')->from($value)->fetch('id'); } $this->session->set('state', $state); } }