備份sql 格式錯誤

能夠順利備份sql資料
但是格式會錯誤
哪裡錯了? 弄一下午


$q1=mysql_query(\"show tables\");
while($t=mysql_fetch_array($q1))
{
$table=$t[0];
$q2=mysql_query(\"show create table `$table`\");
$sql=mysql_fetch_array($q2);
$mysql.=$sql['Create Table'].\";

\";
$q3=mysql_query(\"select * from `$table`\");

while($data=mysql_fetch_assoc($q3))
{
$keys=array_keys($data);
$keys=array_map('addslashes',$keys);
$keys=join('`,`',$keys);
$keys=\"`\".$keys.\"`\";
$vals=array_values($data);
$vals=array_map('addslashes',$vals);
$vals=join(\"','\",$vals);
$vals=\"'\".$vals.\"'\";
$mysql.=\"($vals),
\";
}

}

若是從phpmyadmin直接輸出的格式會是這樣:


DROP TABLE IF EXISTS `a`;
CREATE TABLE IF NOT EXISTS `a` (
`serial` int(255) unsigned NOT NULL AUTO_INCREMENT,
`x` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`x2` varchar(255) COLLATE utf8_unicode_ci NOT NULL
PRIMARY KEY (`serial`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=4 ;

INSERT INTO `a` (`serial`,`x`,`x2`) VALUES
('1','',''),
('2','',''),
('3','','');

若是從我的備份程式下載後會是這樣:

CREATE TABLE `a` (
`serial` int(255) unsigned NOT NULL AUTO_INCREMENT,
`x` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`x2` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`serial`)
) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

('1','',''),
('2','',''),
('3','',''),

如何跟phpmyadmin匯出來的一模一樣?
標籤:
Sign In or Register to comment.