Zhu Jinhui před 7 roky
rodič
revize
f29c13e5c5
5 změnil soubory, kde provedl 347 přidání a 334 odebrání
  1. 11 11
      Qii/Driver/Mysql/Driver.php
  2. 9 9
      Qii/Driver/Mysqli/Driver.php
  3. 284 293
      Qii/Driver/Pdo/Driver.php
  4. 31 9
      _cli.php
  5. 12 12
      _cli/db.ini

+ 11 - 11
Qii/Driver/Mysql/Driver.php

@@ -26,15 +26,15 @@ class Driver extends \Qii\Driver\Base implements \Qii\Driver\Intf
 	/**
 	 * 查询次数
 	 *
-	 * @var int $_queryTimes
+	 * @var int $queryTimes
 	 */
-	public $_queryTimes = 0;
+	public $queryTimes = 0;
 	/**
 	 * 查询耗时
 	 *
-	 * @var array $_querySeconds
+	 * @var array $querySeconds
 	 */
-	public $_querySeconds = array();
+	public $querySeconds = array();
 
 	/**
 	 * 最后一次执行的SQL
@@ -118,17 +118,17 @@ class Driver extends \Qii\Driver\Base implements \Qii\Driver\Intf
 			$error = $this->getError('error');
 			return \Qii::setError(false, __LINE__, 1509, $sql, $error[2] == '' ? 'NULL' : $error[2]);
 		}
-		$this->_queryTimes++;
+		$this->queryTimes++;
 		/**
 		 * 如果调试SQL的话就启用时间的记录
 		 */
 		if ($this->_debugSQL) {
 			$endTime = microtime(true);
 			$costTime = sprintf('%.4f', ($endTime - $startTime));
-			$this->_querySeconds[$this->_queryTimes]['sql'] = $sql;
-			$this->_querySeconds[$this->_queryTimes]['costTime'] = $costTime;
-			$this->_querySeconds[$this->_queryTimes]['startTime'] = $startTime;
-			$this->_querySeconds[$this->_queryTimes]['endTime'] = $endTime;
+			$this->querySeconds[$this->queryTimes]['sql'] = $sql;
+			$this->querySeconds[$this->queryTimes]['costTime'] = $costTime;
+			$this->querySeconds[$this->queryTimes]['startTime'] = $startTime;
+			$this->querySeconds[$this->queryTimes]['endTime'] = $endTime;
 		}
 		return $rs;
 	}
@@ -233,8 +233,8 @@ class Driver extends \Qii\Driver\Base implements \Qii\Driver\Intf
 	public function setError()//设置错误
 	{
 		if (\mysql_errno($this->db['CURRENT'])) {
-			$this->_errorInfo[$this->_queryTimes]['sql'] = $this->sql;
-			$this->_errorInfo[$this->_queryTimes]['error'][2] = \mysql_error($this->db['CURRENT']);
+			$this->_errorInfo[$this->queryTimes]['sql'] = $this->sql;
+			$this->_errorInfo[$this->queryTimes]['error'][2] = \mysql_error($this->db['CURRENT']);
 			$this->response = \Qii\Driver\Response::Fail('pdo.error', $this->_errorInfo);
 		}
 	}

+ 9 - 9
Qii/Driver/Mysqli/Driver.php

@@ -28,13 +28,13 @@ class Driver extends \Qii\Driver\Base implements \Qii\Driver\Intf
 	 *
 	 * @var unknown_type
 	 */
-	public $_queryTimes = 0;
+	public $queryTimes = 0;
 	/**
 	 * 查询耗时
 	 *
 	 * @var INT
 	 */
-	public $_querySeconds = array();
+	public $querySeconds = array();
 
 	/**
 	 * 最后一次执行的SQL
@@ -124,18 +124,18 @@ class Driver extends \Qii\Driver\Base implements \Qii\Driver\Intf
 			$error = $this->getError('error');
 			return \Qii::setError(false, __LINE__, 1509, $sql, $error[2] == '' ? 'NULL' : $error[2]);
 		}
-		$this->_queryTimes++;
 		/**
 		 * 如果调试SQL的话就启用时间的记录
 		 */
 		if ($this->_debugSQL) {
 			$endTime = microtime(true);
 			$costTime = sprintf('%.4f', ($endTime - $startTime));
-			$this->_querySeconds[$this->_queryTimes]['sql'] = $sql;
-			$this->_querySeconds[$this->_queryTimes]['costTime'] = $costTime;
-			$this->_querySeconds[$this->_queryTimes]['startTime'] = $startTime;
-			$this->_querySeconds[$this->_queryTimes]['endTime'] = $endTime;
+			$this->querySeconds[$this->queryTimes]['sql'] = $sql;
+			$this->querySeconds[$this->queryTimes]['costTime'] = $costTime;
+			$this->querySeconds[$this->queryTimes]['startTime'] = $startTime;
+			$this->querySeconds[$this->queryTimes]['endTime'] = $endTime;
 		}
+		$this->queryTimes++;
 		return $rs;
 	}
 
@@ -254,8 +254,8 @@ class Driver extends \Qii\Driver\Base implements \Qii\Driver\Intf
 	public function setError()//设置错误
 	{
 		if (\mysqli_errno($this->db['CURRENT'])) {
-			$this->_errorInfo[$this->_queryTimes]['sql'] = $this->sql;
-			$this->_errorInfo[$this->_queryTimes]['error'][2] = \mysqli_error($this->db['CURRENT']);
+			$this->_errorInfo[$this->queryTimes]['sql'] = $this->sql;
+			$this->_errorInfo[$this->queryTimes]['error'][2] = \mysqli_error($this->db['CURRENT']);
 			$this->response = \Qii\Driver\Response::Fail('pdo.error', $this->_errorInfo);
 		}
 	}

+ 284 - 293
Qii/Driver/Pdo/Driver.php

@@ -5,322 +5,313 @@ namespace Qii\Driver\Pdo;
 
 class Driver extends \Qii\Driver\Base implements \Qii\Driver\Intf
 {
-	const VERSION = '1.2';
-	private static $_instance;
-	protected $connection;
-	private $sysConfigure;
-	private $rs;
-	public $db;
-	/**
-	 * 是否开启调试
-	 *
-	 * @var BOOL
-	 */
-	public $_debugSQL = true;
-	/**
-	 * 执行SQL的列表
-	 *
-	 * @var Array
-	 */
-	public $_exeSQL = array();
-	/**
-	 * 查询次数
-	 *
-	 * @var unknown_type
-	 */
-	public $queryTimes = 0;
-	/**
-	 * 查询耗时
-	 *
-	 * @var INT
-	 */
-	public $querySeconds = array();
+    const VERSION = '1.2';
+    private static $_instance;
+    protected $connection;
+    private $sysConfigure;
+    private $rs;
+    public $db;
+    /**
+     * 是否开启调试
+     *
+     * @var BOOL
+     */
+    public $_debugSQL = true;
+    /**
+     * 执行SQL的列表
+     *
+     * @var Array
+     */
+    public $_exeSQL = array();
+    /**
+     * 查询次数
+     *
+     * @var unknown_type
+     */
+    public $queryTimes = 0;
+    /**
+     * 查询耗时
+     *
+     * @var INT
+     */
+    public $querySeconds = array();
 
-	/**
-	 * 最后一次执行的SQL
-	 *
-	 * @var unknown_type
-	 */
-	private $sql;
-	/**
-	 * 是否开启执行SQL的时间
-	 *
-	 * @var BOOL
-	 */
-	public $_debugTime = false;
-	public $_errorInfo = array();
-	/**
-	 * 保存未定义变量
-	 *
-	 * @var Array
-	 */
-	private $_undefined;
-	/**
-	 * @var string $charset 数据库默认编码
-	 */
-	public $charset = 'UTF8';
-	/**
-	 * 当前使用的db信息
-	 */
-	public $useDB;
-	/**
-	 * @var string $markKey debug信息保存用的key
-	 */
-	public $markKey = '__model';
+    /**
+     * 最后一次执行的SQL
+     *
+     * @var unknown_type
+     */
+    private $sql;
+    /**
+     * 是否开启执行SQL的时间
+     *
+     * @var BOOL
+     */
+    public $_debugTime = false;
+    public $_errorInfo = array();
+    /**
+     * @var string $charset 数据库默认编码
+     */
+    public $charset = 'UTF8';
+    /**
+     * 当前使用的db信息
+     */
+    public $useDB;
+    /**
+     * @var string $markKey debug信息保存用的key
+     */
+    public $markKey = '__model';
     /**
      * @var string $response Response对象
      */
     public $response;
-	/**
-	 * 初始化
-	 * @param \Qii_Driver_ConnIntf $connection 数据库连接
-	 */
-	public function __construct(\Qii\Driver\ConnIntf $connection)
-	{
-		parent::__construct();
-		$this->connection = $connection;
-		$this->sysConfigure = $this->connection->getDBInfo();
-		$this->useDB = $this->sysConfigure['master']['db'];
+
+    /**
+     * 初始化
+     * @param \Qii_Driver_ConnIntf $connection 数据库连接
+     */
+    public function __construct(\Qii\Driver\ConnIntf $connection)
+    {
+        parent::__construct();
+        $this->connection = $connection;
+        $this->sysConfigure = $this->connection->getDBInfo();
+        $this->useDB = $this->sysConfigure['master']['db'];
         $this->response = new \Qii\Driver\Response();
-	}
+    }
 
-	/**
-	 * 用户直接输出这个实例化的类后会输出当前类的名称
-	 *
-	 * @return String
-	 */
-	public function __toString()
-	{
-		return get_class($this);
-	}
+    /**
+     * 用户直接输出这个实例化的类后会输出当前类的名称
+     *
+     * @return String
+     */
+    public function __toString()
+    {
+        return get_class($this);
+    }
 
-	/**
-	 * 查询预处理
-	 * @var string $sql 执行的sql语句
-	 */
-	public function setQuery($sql)
-	{
-		$this->rs = $rs = $this->query($sql);
-		return $rs;
-	}
+    /**
+     * 查询预处理
+     * @var string $sql 执行的sql语句
+     */
+    public function setQuery($sql)
+    {
+        $this->rs = $rs = $this->query($sql);
+        return $rs;
+    }
 
-	/**
-	 * 查询
-	 * @var string $sql 执行的sql语句
-	 */
-	public function query($sql)
-	{
-		/**
-		 * 如果调试SQL的话就启用时间的记录
-		 */
-		if ($this->_debugSQL) {
-			$startTime = microtime(true);
-		}
-		$this->sql = $sql;
-		$this->db['CURRENT'] = $this->connection->getConnectionBySQL($sql);
-		$this->db['CURRENT']->setAttribute(\PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
-		$this->db['CURRENT']->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_WARNING);
+    /**
+     * 查询
+     * @var string $sql 执行的sql语句
+     */
+    public function query($sql)
+    {
+        /**
+         * 如果调试SQL的话就启用时间的记录
+         */
+        if ($this->_debugSQL) {
+            $startTime = microtime(true);
+        }
+        $this->sql = $sql;
+        $this->db['CURRENT'] = $this->connection->getConnectionBySQL($sql);
+        $this->db['CURRENT']->setAttribute(\PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
+        $this->db['CURRENT']->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_WARNING);
         $this->db['CURRENT']->query('set names utf8');
-		$rs = $this->db['CURRENT']->query($sql);
-		$this->setError();
-		if (!$rs) 
-		{
-			$error = $this->getError('error');
-			return \Qii::setError(false, __LINE__, 1509, $sql, $error[2] == '' ? 'NULL' : $error[2]);
-		}
-		$rs->setFetchMode(\PDO::FETCH_ASSOC);
-		$this->queryTimes++;
-		/**
-		 * 如果调试SQL的话就启用时间的记录
-		 */
-		if ($this->_debugSQL) {
-			$endTime = microtime(true);
-			$costTime = sprintf('%.4f', ($endTime - $startTime));
-			$this->querySeconds[$this->queryTimes]['sql'] = $sql;
-			$this->querySeconds[$this->queryTimes]['costTime'] = $costTime;
-			$this->querySeconds[$this->queryTimes]['startTime'] = $startTime;
-			$this->querySeconds[$this->queryTimes]['endTime'] = $endTime;
-		}
-		return $rs;
-	}
+        $rs = $this->db['CURRENT']->query($sql);
+        $this->setError();
+        if (!$rs) {
+            $error = $this->getError('error');
+            return \Qii::setError(false, __LINE__, 1509, $sql, $error[2] == '' ? 'NULL' : $error[2]);
+        }
+        $rs->setFetchMode(\PDO::FETCH_ASSOC);
+        /**
+         * 如果调试SQL的话就启用时间的记录
+         */
+        if ($this->_debugSQL) {
+            $endTime = microtime(true);
+            $costTime = sprintf('%.4f', ($endTime - $startTime));
+            $this->querySeconds[$this->queryTimes]['sql'] = $sql;
+            $this->querySeconds[$this->queryTimes]['costTime'] = $costTime;
+            $this->querySeconds[$this->queryTimes]['startTime'] = $startTime;
+            $this->querySeconds[$this->queryTimes]['endTime'] = $endTime;
+        }
+        $this->queryTimes++;
+        return $rs;
+    }
 
-	/**
-	 * 获取一行
-	 *
-	 * @param Resource $rs
-	 * @return Array
-	 */
-	public function fetch($rs = null)
-	{
-		if (!$rs) return $this->rs->rech();
-		return $rs->fetch();
-	}
+    /**
+     * 获取一行
+     *
+     * @param Resource $rs
+     * @return Array
+     */
+    public function fetch($rs = null)
+    {
+        if (!$rs) return $this->rs->rech();
+        return $rs->fetch();
+    }
 
-	/**
-	 * 执行SQL
-	 *
-	 * @param String $sql
-	 * @return Int
-	 */
-	public function exec($sql)
-	{
-		$this->rs = $this->query($sql);
-		return $this->affectedRows();
-	}
+    /**
+     * 执行SQL
+     *
+     * @param String $sql
+     * @return Int
+     */
+    public function exec($sql)
+    {
+        $this->rs = $this->query($sql);
+        return $this->affectedRows();
+    }
 
-	/**
-	 * 设置获取数据的类型
-	 *
-	 */
-	public function setFetchMode()
-	{
-		$this->rs->setFetchMode(PDO::FETCH_ASSOC);
-	}
+    /**
+     * 设置获取数据的类型
+     *
+     */
+    public function setFetchMode()
+    {
+        $this->rs->setFetchMode(PDO::FETCH_ASSOC);
+    }
 
-	/**
-	 * 获取一行
-	 * @var string $sql 获取一行
-	 * @return array 返回数据
-	 */
-	public function getRow($sql)
-	{
-		if (!$this->sysConfigure['driver'] == 'mssql' && !preg_match("/LIMIT(\s){1,}(\d){1,},(\s){0,}(\d){1,}/ui", $sql) && !preg_match("/LIMIT(\s){1,}(\d){1,}/ui", $sql)) {
-			$sql = $sql . " LIMIT 1";
-		} else if ($this->sysConfigure['driver'] == 'mssql' && !preg_match("/^SELECT(\s)TOP(\s)(\d){1,}/i", $sql)) {
-			$sql = preg_replace("/^SELECT(\s)/i", "SELECT TOP 1 ", $sql);
-		}
-		$this->rs = $rs = $this->setQuery($sql);
-		return $rs->fetch();
-	}
+    /**
+     * 获取一行
+     * @var string $sql 获取一行
+     * @return array 返回数据
+     */
+    public function getRow($sql)
+    {
+        if (!$this->sysConfigure['driver'] == 'mssql' && !preg_match("/LIMIT(\s){1,}(\d){1,},(\s){0,}(\d){1,}/ui", $sql) && !preg_match("/LIMIT(\s){1,}(\d){1,}/ui", $sql)) {
+            $sql = $sql . " LIMIT 1";
+        } else if ($this->sysConfigure['driver'] == 'mssql' && !preg_match("/^SELECT(\s)TOP(\s)(\d){1,}/i", $sql)) {
+            $sql = preg_replace("/^SELECT(\s)/i", "SELECT TOP 1 ", $sql);
+        }
+        $this->rs = $rs = $this->setQuery($sql);
+        return $rs->fetch();
+    }
 
-	/**
-	 * 获取一列
-	 * @var string $sql 需要获取一列的sql语句
-	 * @return strin | bool 返回其中一列或者是false
-	 */
-	public function getOne($sql)
-	{
-		$rs = $this->setQuery($sql);
-		if ($rs) {
-			return $rs->fetchColumn();
-		}
-		return false;
-	}
+    /**
+     * 获取一列
+     * @var string $sql 需要获取一列的sql语句
+     * @return strin | bool 返回其中一列或者是false
+     */
+    public function getOne($sql)
+    {
+        $rs = $this->setQuery($sql);
+        if ($rs) {
+            return $rs->fetchColumn();
+        }
+        return false;
+    }
 
-	/**
-	 * 获取所有的行
-	 * @var string $sql 需要获取所有行的sql语句
-	 * @return array
-	 */
-	public function getAll($sql)
-	{
-		$this->rs = $rs = $this->setQuery($sql);
-		return $rs->fetchAll();
-	}
+    /**
+     * 获取所有的行
+     * @var string $sql 需要获取所有行的sql语句
+     * @return array
+     */
+    public function getAll($sql)
+    {
+        $this->rs = $rs = $this->setQuery($sql);
+        return $rs->fetchAll();
+    }
 
-	/**
-	 * 事务处理
-	 */
-	public function transaction()
-	{
-		$this->db['CURRENT']->beginTransaction();
-	}
+    /**
+     * 事务处理
+     */
+    public function transaction()
+    {
+        $this->db['CURRENT']->beginTransaction();
+    }
 
-	/**
-	 * 事务提交
-	 */
-	public function commit()
-	{
-		$this->db['CURRENT']->commit();
-	}
+    /**
+     * 事务提交
+     */
+    public function commit()
+    {
+        $this->db['CURRENT']->commit();
+    }
 
-	/**
-	 * 事务回滚
-	 */
-	public function rollback()
-	{
-		$this->db['CURRENT']->rollBack();
-	}
+    /**
+     * 事务回滚
+     */
+    public function rollback()
+    {
+        $this->db['CURRENT']->rollBack();
+    }
 
-	/**
-	 * 影响的行数
-	 *
-	 * @return Int
-	 */
-	public function affectedRows()
-	{
-		if (!$this->rs) return false;
-		return $this->rs->rowCount();
-	}
+    /**
+     * 影响的行数
+     *
+     * @return Int
+     */
+    public function affectedRows()
+    {
+        if (!$this->rs) return false;
+        return $this->rs->rowCount();
+    }
 
-	/**
-	 * 最后插入到数据库的自增长ID
-	 *
-	 * @return Int
-	 */
-	public function lastInsertId()
-	{
-		return $this->db['CURRENT']->lastInsertId();
-	}
+    /**
+     * 最后插入到数据库的自增长ID
+     *
+     * @return Int
+     */
+    public function lastInsertId()
+    {
+        return $this->db['CURRENT']->lastInsertId();
+    }
 
-	/**
-	 * 获取最后一次出错的信息
-	 *
-	 * @return Array
-	 */
-	public function getError($key = '')
-	{
-		$errorInfo = array_pop($this->_errorInfo);
-		if ($errorInfo) {
-			//将错误加回来
-			array_push($this->_errorInfo, $errorInfo);
-			if (!empty($key)) {
-				return $errorInfo[$key];
-			}
-			return $errorInfo;
-		}
-		return null;
-	}
+    /**
+     * 获取最后一次出错的信息
+     *
+     * @return Array
+     */
+    public function getError($key = '')
+    {
+        $errorInfo = array_pop($this->_errorInfo);
+        if ($errorInfo) {
+            //将错误加回来
+            array_push($this->_errorInfo, $errorInfo);
+            if (!empty($key)) {
+                return $errorInfo[$key];
+            }
+            return $errorInfo;
+        }
+        return null;
+    }
 
-	/**
-	 * 是否有错,有错误的话存储错误
-	 *
-	 */
-	public function setError()
-	{
-		if ($this->connection->getConnectionBySQL($this->sql)->errorCode() != '00000') {
-			$this->_errorInfo[$this->queryTimes]['sql'] = $this->sql;
-			$this->_errorInfo[$this->queryTimes]['error'] = $this->connection->getConnectionBySQL($this->sql)->errorInfo();
-			$this->response = \Qii\Driver\Response::Fail('pdo.error', $this->_errorInfo);
-		}
-	}
+    /**
+     * 是否有错,有错误的话存储错误
+     *
+     */
+    public function setError()
+    {
+        if ($this->connection->getConnectionBySQL($this->sql)->errorCode() != '00000') {
+            $this->_errorInfo[$this->queryTimes]['sql'] = $this->sql;
+            $this->_errorInfo[$this->queryTimes]['error'] = $this->connection->getConnectionBySQL($this->sql)->errorInfo();
+            $this->response = \Qii\Driver\Response::Fail('pdo.error', $this->_errorInfo);
+        }
+    }
 
-	/**
-	 * 是否执行出错
-	 *
-	 * @return Bool
-	 */
-	public function isError()
-	{
-		if(!$this->rs)
-		{
-			return true;
-		}
-		$errorInfo = $this->rs->errorInfo();
-		if ($this->connection->getConnectionBySQL($this->sql)->errorCode() != '00000') 
-		{
-			return true;
-		}
-		return false;
-	}
+    /**
+     * 是否执行出错
+     *
+     * @return Bool
+     */
+    public function isError()
+    {
+        if (!$this->rs) {
+            return true;
+        }
+        if ($this->connection->getConnectionBySQL($this->sql)->errorCode() != '00000') {
+            return true;
+        }
+        return false;
+    }
 
-	/**
-	 * 返回response对象
-	 *
-	 * @return Bool
-	 */
-	public function getResponse()
-	{
-		return $this->response;
-	}
+    /**
+     * 返回response对象
+     *
+     * @return Bool
+     */
+    public function getResponse()
+    {
+        return $this->response;
+    }
 }

+ 31 - 9
_cli.php

@@ -27,27 +27,45 @@ class cmd
     public function __construct($args)
     {
         $param = $this->parseArgvs($args);
-        if (sizeof($param) < 1) {
+        if (sizeof($param) < 1 || ($param['dbHost'] != '' && sizeof($param) < 7)) {
             $this->stdout("命令行使用如下:\n
->php -q _cli.php create=yes workspace=../project cache=tmp useDB=1\n
+>php -q _cli.php create=yes workspace=../project cache=tmp dbHost=localhost dbName=test dbUser=root dbPassword=test\n
  * create: 是否自动创建:yes; \n
  * workspace: 工作目录\n
  * cache : 缓存目录\n
- * useDB : 是否使用数据库 : 使用:1 不使用: 0\n
+ * dbHost : 数据库服务器IP\n
+ * dbName : 数据库名称 : \n
+ * dbUser : 数据库用户名\n
+ * dbPassword : 数据库密码 : \n
  ");
-            $this->stdout("创建 yes/no:");
+            $this->stdout("是否自动创建 yes/no:");
             $param['create'] = trim(fgets(\STDIN));
             $this->stdout("工作目录:");
             $param['workspace'] = trim(fgets(\STDIN));
             $this->stdout("缓存目录:");
             $param['cache'] = trim(fgets(\STDIN));
-            $this->stdout("是否使用数据库 使用:1 不使用 0:");
-            $param['useDB'] = trim(fgets(\STDIN));
+            
+            $this->stdout('数据库服务器IP:');
+            $param['dbHost'] = trim(fgets(\STDIN));
+            if(!$param['dbHost']) $param['dbHost'] = 'localhost';
+            $this->stdout("数据库名称:");
+            $param['dbName'] = trim(fgets(\STDIN));
+
+            $this->stdout('请输入数据库用户名:');
+            $param['dbUser'] = trim(fgets(\STDIN));
+
+            $this->stdout('请输入数据库密码:');
+            $param['dbPassword'] = trim(fgets(\STDIN));
 
             $this->stdout('将要在'. $param['workspace'] .'创建项目,确认请输入yes,取消请输入no:');
 
             $param['create'] = trim(fgets(\STDIN));
         }
+        $param['useDB'] = 0;
+        if($param['dbName'] != '')
+        {
+            $param['useDB'] = 1;
+        }
         if ($param['create'] == 'yes') {
             if ($this->workspace($param['workspace'])) {
                 $cache = $param['cache'];
@@ -94,9 +112,13 @@ class cmd
                     $this->stdout('拷贝 router.config.php 到' . $param['workspace'] . '/private/Configure/router.config.php 失败, 拒绝访问.');
                 }
                 if ($param['useDB'] != 'no') {
-                    if (!copy("_cli/db.ini", $param['workspace'] . '/private/Configure/db.ini')) {
-                        $this->stdout('拷贝 db.ini 到 ' . $param['workspace'] . '/private/Configure/db.ini false, 拒绝访问.');
-                    }
+                    $dbIni = file_get_contents('_cli/db.ini');
+                    $dbIni = str_replace('DB_NAME', $param['dbName'], $dbIni);
+                    $dbIni = str_replace('DB_HOST', $param['dbHost'], $dbIni);
+                    $dbIni = str_replace('DB_USER', $param['dbUser'], $dbIni);
+                    $dbIni = str_replace('DB_PASSWORD', $param['dbPassword'], $dbIni);
+                    
+                    file_put_contents($param['workspace'] . '/private/Configure/db.ini', $dbIni);
                 }
 
                 //生成数据库文件

+ 12 - 12
_cli/db.ini

@@ -5,20 +5,20 @@ readOrWriteSeparation = 0
 driver = pdo
 ;使用的数据库类型
 use_db_driver = mysql
-master[db] = test
-master[host] = 127.0.0.1
-master[user] = root
-master[password] = 
+master[db] = DB_NAME
+master[host] = DB_HOST
+master[user] = DB_USER
+master[password] = DB_PASSWORD
 
-slave[0.db] = test
-slave[0.host] = 127.0.0.1
-slave[0.user] = root
-slave[0.password] = 
+slave[0.db] = DB_NAME
+slave[0.host] = DB_HOST
+slave[0.user] = DB_USER
+slave[0.password] = DB_PASSWORD
 
 
-slave[1.db] = test
-slave[1.host] = 127.0.0.1
-slave[1.user] = root
-slave[1.password] = 
+slave[1.db] = DB_NAME
+slave[1.host] = DB_HOST
+slave[1.user] = DB_USER
+slave[1.password] = DB_PASSWORD
 
 [product:common]