简体   繁体   English

试图使用PHP备份MySQL数据库

[英]trying to backup mysql database using php

I got this code from this site: http://www.php-mysql-tutorial.com/wikis/mysql-tutorials/using-php-to-backup-mysql-databases.aspx 我从以下站点获得了此代码: http : //www.php-mysql-tutorial.com/wikis/mysql-tutorials/using-php-to-backup-mysql-databases.aspx

But I'm just a beginner so I don't know what the config.php and opendb.php suppose to mean. 但是我只是一个初学者,所以我不知道config.php和opendb.php的含义。 Do I have to create those 2 files in order for this code to work? 为了使此代码正常工作,我是否必须创建这两个文件? If yes, then how do I create it, it isn't included in the site how to create it. 如果是,那么我如何创建它,它不包含在网站中。

<?php
include 'config.php';
include 'opendb.php';

$tableName  = 'mypet';
$backupFile = 'backup/mypet.sql';
$query      = "SELECT * INTO OUTFILE '$backupFile' FROM $tableName";
$result = mysql_query($query);

include 'closedb.php';
?> 

can I just include these lines on the top code so that I will not be putting the include 'opendb.php' anymore: 我可以在最上面的代码中包括这些行,以便不再使用include'opendb.php'吗:

$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("Hospital", $con);

Yes you need those two files and the other closedb.php included in your script. 是的,您需要脚本中包含的两个文件和另一个closedb.php。 As the name suggests, config.php most likely contains the DB parameters: user, pass, host, dbname while opendb.php and closedb.php will contain the routines to connect and close your DB. 顾名思义,config.php很可能包含数据库参数:user,pass,host,dbname,而opendb.php和closedb.php将包含连接和关闭数据库的例程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM