Home >Backend Development >PHP Tutorial >PHP export Mysql to .sql file_PHP tutorial

PHP export Mysql to .sql file_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-13 17:44:27793browse

php代码:

01.
02.
03.$database=test;//Database name
04.
05.$options=array(
06.
07. hostname => localhost,//ip address
08.
09. charset => utf-8,//encoding
10.
11. filename => $database. .sql,//File name
12.
13. username => root,
14.
15. password => 123123
16.
17.);
18.
19.mysql_connect($options [hostname],$options[username ],$options[password]) or die("Unable to connect to database!");
20.
21.mysql_select_db($database ) or die("Wrong database name!");
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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478755.htmlTechArticlephp code: 01. ?php 02. 03. $database = test; //Database name 04. 05. $options = array ( 06 . 07 . hostname = localhost , //ip address 08. 09. charset = utf-8 , //encoding 10 . 1...
Statement:
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