发布时间:2015-05-27 19:28:22作者:知识屋
[php]
<?php
require_once('configuration.php');
$jconfig = new JConfig();
$connect = mysql_connect($jconfig->host ,$jconfig->user, $jconfig->password);
$result = mysql_list_tables($jconfig->db);
$tables = array();
while ($row = mysql_fetch_row($result)) {
$tables[] = $row[0];
}
mysql_select_db($jconfig->db);
$sql = '';
foreach($tables as $table){
$sql .= backupTable($table);
}
$r = file_put_contents('tmp/backup_'.date('Y-m-d-H-i-s').'.sql', $sql);
if($r){
die('success');
}else{
die('lalala');
}
mysql_close($connect);
function backupTable($table){
$sqltxt = "DROP TABLE IF EXISTS $table;/n";
$result = mysql_query("SHOW CREATE TABLE $table");
$row = mysql_fetch_assoc($result);
$createsql = $row['Create Table'];
$sqltxt .= $createsql.";/n/n";
$result = mysql_query("SELECT * FROM $table");
$rows = array();
while($row = mysql_fetch_assoc($result)){
$fields = array();
foreach($row as $field){
$fields[] = '/''.mysql_escape_string($field).'/'';
}
$rows[] = '('.implode(',', $fields).')';
}
if(!emptyempty($rows)){
$sqltxt .= "INSERT INTO `$table` VALUES".implode(",/n", $rows).";/n";
}
$sqltxt .= "/n";
return $sqltxt;
}
<?php
require_once('configuration.php');
$jconfig = new JConfig();
$connect = mysql_connect($jconfig->host ,$jconfig->user, $jconfig->password);
$result = mysql_list_tables($jconfig->db);
$tables = array();
while ($row = mysql_fetch_row($result)) {
$tables[] = $row[0];
}
mysql_select_db($jconfig->db);
$sql = '';
foreach($tables as $table){
$sql .= backupTable($table);
}
$r = file_put_contents('tmp/backup_'.date('Y-m-d-H-i-s').'.sql', $sql);
if($r){
die('success');
}else{
die('lalala');
}
mysql_close($connect);
function backupTable($table){
$sqltxt = "DROP TABLE IF EXISTS $table;/n";
$result = mysql_query("SHOW CREATE TABLE $table");
$row = mysql_fetch_assoc($result);
$createsql = $row['Create Table'];
$sqltxt .= $createsql.";/n/n";
$result = mysql_query("SELECT * FROM $table");
$rows = array();
while($row = mysql_fetch_assoc($result)){
$fields = array();
foreach($row as $field){
$fields[] = '/''.mysql_escape_string($field).'/'';
}
$rows[] = '('.implode(',', $fields).')';
}
if(!empty($rows)){
$sqltxt .= "INSERT INTO `$table` VALUES".implode(",/n", $rows).";/n";
}
$sqltxt .= "/n";
return $sqltxt;
}
如何对PHP文件进行加密方法 PHP实现加密的几种方式介绍
php生成圆角图片的方法 电脑中php怎么生成圆角图片教程
用PHP构建一个留言本方法步骤 php怎么实现留言板功能
php中三元运算符用法 php中的三元运算符使用说明
php文件如何怎么打开方式介绍 php文件用什么打开方法
PHP怎么插入数据库方法步骤 php编程怎么导入数据库教程
如何安装PHPstorm并配置方法教程 phpstorm安装后要进行哪些配置
PHP 获取远程文件大小的3种解决方法 如何用PHP获取远程大文件的大小
20个实用PHP实例代码 php接口开发实例代码详细介绍
如何架设PHP服务器方法步骤 怎么搭建php服务器简单教程