diff --git a/test/lib/db.class.php b/test/lib/db.class.php index e0cc0cf622..71a3b48d09 100644 --- a/test/lib/db.class.php +++ b/test/lib/db.class.php @@ -145,8 +145,14 @@ class db { $this->dao->query('DROP DATABASE IF EXISTS ' . $this->config->test->dbPrefix . $i); $this->dao->query('CREATE DATABASE ' . $this->config->test->dbPrefix . $i); - - shell_exec("mysql -h{$this->config->db->host} -u {$this->config->db->user} -p{$this->config->db->password} -P {$this->config->db->port} {$this->config->test->dbPrefix}{$i} < {$this->sqlFile}"); + if($this->config->db->host = 'localhost' and $this->config->db->port = '3306') + { + shell_exec("mysql -u {$this->config->db->user} -p{$this->config->db->password} {$this->config->test->dbPrefix}{$i} < {$this->sqlFile}"); + } + else + { + shell_exec("mysql -h{$this->config->db->host} -u {$this->config->db->user} -p{$this->config->db->password} -P {$this->config->db->port} {$this->config->test->dbPrefix}{$i} < {$this->sqlFile}"); + } } } } diff --git a/test/lib/utils.php b/test/lib/utils.php index 60e0f6a9d5..baa2b68448 100755 --- a/test/lib/utils.php +++ b/test/lib/utils.php @@ -218,12 +218,19 @@ function zdRun() function copyDB() { global $config, $dao; - - $dumpCommand = "mysqldump -h%s -P%s -u%s -p%s %s --add-drop-table=false > %s"; - $sqlFile = TEST_BASEHPATH . DS . 'tmp/raw.sql'; + $sqlFile = TEST_BASEHPATH . DS . 'tmp/raw.sql'; + if($config->db->host = 'localhost' and $config->db->port = '3306') + { + $dumpCommand = "mysqldump -u%s -p%s %s --add-drop-table=false > %s"; + $dumpCommand = sprintf($dumpCommand, $config->db->user, $config->db->password, $config->test->rawDB, $sqlFile); + } + else + { + $dumpCommand = "mysqldump -h%s -P%s -u%s -p%s %s --add-drop-table=false > %s"; + $dumpCommand = sprintf($dumpCommand, $config->db->host, $config->db->port, $config->db->user, $config->db->password, $config->test->rawDB, $sqlFile); + } $currentDBNum = $dao->query("select count(*) as num from information_schema.SCHEMATA where SCHEMA_NAME like '" . $config->test->dbPrefix . "%'")->fetch(); - $dumpCommand = sprintf($dumpCommand, $config->db->host, $config->db->port, $config->db->user, $config->db->password, $config->test->rawDB, $sqlFile); shell_exec($dumpCommand); $dbNum = $config->test->dbNum; @@ -238,7 +245,14 @@ function copyDB() { if($currentDBNum->num > 0) $dao->query('DROP DATABASE IF EXISTS ' . $db); $dao->query('CREATE DATABASE ' . $db); - shell_exec("mysql -h{$config->db->host} -P {$config->db->port} -u{$config->db->user} -p{$config->db->password} $db < $sqlFile"); + if($config->db->host = 'localhost' and $config->db->port = '3306') + { + shell_exec("mysql -u{$config->db->user} -p{$config->db->password} $db < $sqlFile"); + } + else + { + shell_exec("mysql -h{$config->db->host} -P {$config->db->port} -u{$config->db->user} -p{$config->db->password} $db < $sqlFile"); + } echo '数据库<' . $db . '>复制成功!' . PHP_EOL; } }