Export Mysql into A. SQL file using PHP

Source: Internet
Author: User
Php code: 01. & lt ;? Php02. & nbsp; 03. $ databasetest; // database name 04. & nbsp; 05. $ optionsarray (06. & nbsp; 07. & nbsp; hostname & gt; localhost, // IP address 08. & nbsp; 09. & nbsp; charset & g

Php code:

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])OrDie("Cannot connect to the database! ");
20.
21.Mysql_select_db($ Database)OrDie("The database name is incorrect! ");
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); // Specify the name of the exported table or use the following statement to export the entire database
32.
33./*
34.
35. foreach ($ tables as $ table ){
36.
37. dump_table ($ table, $ fp );
38.
39 .}
40.
41 .*/
42.
43.Fclose($ Fp);
44.
45.// Download the SQL file
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.// Delete the SQL file on the server
56.
57.Unlink($ File_name);
58.
59.Exit;
60.
61.// Obtain the table name
62.
63.FunctionList_tables($ Database)
64.
65.{
66.
67.$ Rs = Mysq

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.