PHP导出Mysql成.sql文件_PHP教程
时间:2021-07-01 10:21:17
帮助过:18人阅读
php代码:
01.
02.
03.$database=test;//数据库名
04.
05.$options=array(
06.
07. hostname => localhost,//ip地址
08.
09. charset => utf-8,//编码
10.
11. filename => $database..sql,//文件名
12.
13. username => root,
14.
15. password => 123123
16.
17.);
18.
19.mysql_connect($options[hostname],$options[username],$options[password])or die("不能连接数据库!");
20.
21.mysql_select_db($database) or die("数据库名称错误!");
22.
23.mysql_query("SET NAMES {$options[charset]}");
24.
25.$tables = list_tables($database);
26.
27.$filename = sprintf($options[filename],$database);
28.
29.$fp = fopen($filename, w);
30.
31.dump_table(my_member, $fp); //指定导出的表名,或使用下面语句导出整库
32.
33./*
34.
35.foreach ($tables as $table) {
36.
37. dump_table($table, $fp);
38.
39.}
40.
41.*/
42.
43.fclose($fp);
44.
45.//下载sql文件
46.
47.$file_name=$options[filename];
48.
49.Header("Content-type:application/octet-stream");
50.
51.Header("Content-Disposition:attachment;filename=".$file_name);
52.
53.readfile($file_name);
54.
55.//删除服务器上的sql文件
56.
57.unlink($file_name);
58.
59.exit;
60.
61.//获取表的名称
62.
63.function list_tables($database)
64.
65.{
66.
67. $rs = mysq
http://www.bkjia.com/PHPjc/478755.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/478755.htmlTechArticlephp代码: 01. ?php 02 . 03 . $database = test ; //数据库名 04 . 05 . $options = array ( 06 . 07 . hostname = localhost , //ip地址 08. 09. charset = utf-8 , //编码 10 . 1...