PHP导出Mysql的sql语句
admin | 网络闲聊 | 七月 17th, 2007 | No Comments »
<?php
$host="localhost";
$user="root";
$password="";
$dbname="dbname";
mysql_connect($host,$user,$password);
mysql_select_db($dbname);
$mysql= “set charset gb2312;\r\n”;#for mysql>=5.0
$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’].“;\r\n\r\n”;#DDL
$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_s($data);
$vals=array_map(‘addslashes’,$vals);
$vals=join(“‘,'”,$vals);
$vals=“‘”.$vals.“‘”;
$mysql.=“insert into `$table`($keys) s($vals);\r\n”;
}
$mysql.=“\r\n”;
}
echo $mysql;#若用记事本打开,粘贴,应该取消‘自动换行’
?>
发表评论
你必须 登录 才能发表评论.