59 lines
1.8 KiB
PHP
59 lines
1.8 KiB
PHP
<?php
|
|
/**
|
|
* The model file of convert module of ZenTaoMS.
|
|
*
|
|
* ZenTaoMS is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* ZenTaoMS is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU Lesser General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
* along with ZenTaoMS. If not, see <http://www.gnu.org/licenses/>.
|
|
*
|
|
* @copyright Copyright: 2009 Chunsheng Wang
|
|
* @author Chunsheng Wang <wwccss@263.net>
|
|
* @package convert
|
|
* @version $Id$
|
|
* @link http://www.zentao.cn
|
|
*/
|
|
?>
|
|
<?php
|
|
class convertModel extends model
|
|
{
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->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();
|
|
}
|
|
}
|