The backup database code is valid locally, and uploading to the server is invalid. what is the problem?-php Tutorial

Source: Internet
Author: User
The backup database code is valid locally, and uploading data to the server is invalid. what's wrong? why can the following code be used during local testing, however, uploading to the server becomes invalid ?????
// Back up the database
Require ('Des/config. php ');
// The account, password, and name are all uploaded from the page.
$ User_id = isset ($ _ REQUEST ['id'])? Intval (trim ($ _ REQUEST ['id']): 1;
If (! Mysql_connect ($ db_host, $ db_user, $ db_pass) // connect to the mysql database
{
Echo 'database connection failed. check the database and try again ';
Exit;
}
If (! Mysql_select_db ($ db_name) // check whether the database exists
{
Echo 'database does not exist: '. $ db_name.'. check the database and try again ';
Exit;
}
Mysql_query ("set names 'utf8 '");
$ Mysql = "set names utf8; \ r \ n ";
$ 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 ";
$ 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_values ($ data );
$ Vals = array_map ('addslashes', $ vals );
$ Vals = join ("','", $ vals );
$ Vals = "'". $ vals ."'";
$ Mysql. = "insert into '$ table' ($ keys) values ($ vals); \ r \ n ";
}
}

$ Filename = $ db_name. "_". date ('Y-m-D', time ()). ". SQL "; // storage path, which is stored in the outermost layer of the project by default
$ File = "my_ SQL/". $ filename;
$ Fp = fopen (dirname (_ FILE _). "\". "my_ SQL \". $ filename, 'w ');
Fputs ($ fp, $ mysql );

If (file_exists ($ file ))
{
Header ('content-Description: File Transfer ');
Header ('content-Type: application/octet-stream ');
Header ('content-Disposition: attachment; filename = '. basename ($ file ));
Header ('content-Transfer-Encoding: binary ');
Header ('expires: 0 ');
Header ('cache-Control: must-revalidate, post-check = 0, pre-check = 0 ');
Header ('pragma: public ');
Header ('content-Length: '. filesize ($ file ));
Ob_clean ();
Flush ();
Readfile ($ file );
}

Fclose ($ fp );
?>


Reply to discussion (solution)

Is there any function or component to be enabled on the server ??

If there is a mistake, there should be an error message

I don't know what your "invalid" refers.

There are no prompts on the server. you can test it locally.

No prompt. it may be that the error is not displayed.
You can take the initiative to output something at the end of each step to determine where the problem is.

OK. it's the path. thank you.

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.