From 75377f368d88543419c0f9a55633501869d6b356 Mon Sep 17 00:00:00 2001 From: liyang Date: Thu, 22 Sep 2022 09:50:17 +0800 Subject: [PATCH 1/2] * Fix copy db. --- test/lib/db.class.php | 10 ++++++++-- test/lib/utils.php | 24 +++++++++++++++++++----- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/test/lib/db.class.php b/test/lib/db.class.php index e0cc0cf622..b04064d8e9 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..80ede45bb5 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; } } From c31279d5da8dd18ae95617a24cb987581f5da766 Mon Sep 17 00:00:00 2001 From: liyang Date: Thu, 22 Sep 2022 11:25:59 +0800 Subject: [PATCH 2/2] * Fix format. --- test/lib/db.class.php | 2 +- test/lib/utils.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/lib/db.class.php b/test/lib/db.class.php index b04064d8e9..71a3b48d09 100644 --- a/test/lib/db.class.php +++ b/test/lib/db.class.php @@ -145,7 +145,7 @@ class db { $this->dao->query('DROP DATABASE IF EXISTS ' . $this->config->test->dbPrefix . $i); $this->dao->query('CREATE DATABASE ' . $this->config->test->dbPrefix . $i); - if($this->config->db->host = 'localhost' and $this->config->db->port = '3306') + 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}"); } diff --git a/test/lib/utils.php b/test/lib/utils.php index 80ede45bb5..baa2b68448 100755 --- a/test/lib/utils.php +++ b/test/lib/utils.php @@ -219,7 +219,7 @@ function copyDB() { global $config, $dao; $sqlFile = TEST_BASEHPATH . DS . 'tmp/raw.sql'; - if($config->db->host = 'localhost' and $config->db->port = '3306') + 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); @@ -245,7 +245,7 @@ function copyDB() { if($currentDBNum->num > 0) $dao->query('DROP DATABASE IF EXISTS ' . $db); $dao->query('CREATE DATABASE ' . $db); - if($config->db->host = 'localhost' and $config->db->port = '3306') + if($config->db->host = 'localhost' and $config->db->port = '3306') { shell_exec("mysql -u{$config->db->user} -p{$config->db->password} $db < $sqlFile"); }