[英]How can i fetch all data from any table of a test DB and DUMP it on the production db in same tablename(structure)?
如何從測試數據庫的任何表中獲取所有數據,並將其轉儲到生產數據庫中的同一表名(結構)中? 在MySQL中使用PHP代碼?
請幫我..
編輯
我需要PHP使用MySQL查詢為我完成此操作
抱歉,有些混亂,但是這些是我用來構建用於表重建和重新填充的SQL代碼的功能。 所有這些都在“表”對象中,但是我敢肯定您可以將發生的事情拼湊在一起。
SQL“ SHOW CREATE TABLE yourtablename”為您提供了再次創建表所需的一切。 其余所有內容僅遍歷所有條目並生成INSERT語句。
public function backup() {
$output = "/* - - - Table recovery for $this->tablename - - - */\n\n\n";
$output .= "DROP TABLE IF EXISTS `$this->tablename`;\n\n";
$output .= $this->showcreate().';';
$output .= $this->showrepopulate();
return $output."\n\n\n";
}
final protected function showcreate() {
$result = $this->query("SHOW CREATE TABLE $this->tablename");
return $result[0]['Create Table'];
}
final protected function showrepopulate() {
$result = $this->query("SELECT * FROM $this->tablename");
$output = '';
$count = count($result);
if ($count) {
$output = "\n\nINSERT INTO `$this->tablename` VALUES\n";
for ($i=0; $i<$count; $i++) {
$output .= "(";
$numfields = count($result[$i]);
for ($j=0; $j<$numfields; $j++) {
if ($j>0) $output .= ',';
$output .= $this->Database->escape(array_shift($result[$i]));
}
$output .= ")";
$output .= ($i != $count-1) ? ",\n" : ';';
}
}
return $output;
}
如果要通過轉儲創建SQL代碼來重新創建表的方法,則建議使用現有工具來管理MySQL,例如phpMyAdmin或Adminer。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.