. * * @copyright Copyright: 2009 Chunsheng Wang * @author Chunsheng Wang * @package convert * @version $Id$ * @link http://www.zentao.cn */ ?> connectDB(); } /* 连接到数据库。*/ public function connectDB() { $dsn = "mysql:host={$this->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 UTF8"); $this->sourceDBH = $dbh; } catch (PDOException $exception) { return $exception->getMessage(); } } /* 判断数据库是否存在。*/ public function dbExists() { $sql = "SHOW DATABASES like '{$this->post->db->name}'"; return $this->dbh->query($sql)->fetch(); } }