Home > php教程 > php手册 > PHP导出Mysql成.sql文件

PHP导出Mysql成.sql文件

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 10:42:56
Original
1216 people have browsed it

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
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template