导出mysql数据表 Monxin专用(PHP代码函数)
来源:互联网 发布:邮政储蓄网络培训学院 编辑:程序博客网 时间:2024/05/16 06:32
//导出mysql数据表 Monxin专用(PHP代码函数)
//本代码基于Monxin 运行
//代码来源:Monxin ./config/functions.php
function output_table($pdo,$save_dir,$program='',$flag=1){
set_time_limit(0);
$mysql='monxin_sql_start';
if($program!=''){
$statments=$pdo->query("show tables like '".$pdo->sys_pre.$program."_%'");
}else{
$statments=$pdo->query("show tables like '".$pdo->sys_pre."%'");
}
$file_count=0;
$save_dir.='/';
$save_dir=str_replace('//','/',$save_dir.'/');
$save_path=$save_dir.date('Y-m-d_H-i',time()).'_'.rand(100,99999).'__';
$files=array();
foreach ($statments as $value) {
$table_name=$value[0];
$mysql.="DROP TABLE IF EXISTS `$table_name`;m;o;n;\n\r";
$table_query=$pdo->query("show create table `$table_name`");
$create_sql=$table_query->fetch();
$mysql.=$create_sql['Create Table'] .";m;o;n;\n\r";
if ($flag != 0) {
$iteams_query=$pdo->query("select * from `$table_name`");
$values="";
$items="";
$i=0;
while ($item_query=$iteams_query->fetch(PDO::FETCH_ASSOC)){
$i++;
$item_names=array_keys($item_query);
$item_names=array_map("addslashes", $item_names);
$items=join('`,`', $item_names);
$item_values=array_values($item_query);
$item_values=array_map("addslashes", $item_values);
$value_string=join("','", $item_values);
$value_string="('" . $value_string . "'),";
$values.="\n" . $value_string;
if($i==50){
$mysql.= "INSERT INTO `$table_name` (`$items`) VALUES" . rtrim($values, ",") . ";m;o;n;\n\r";
$i=0;
$items='';
$values='';
}
if(strlen($mysql)>(1024*1024*10)){
$file_count++;
file_put_contents($save_path.$file_count.'.sql',$mysql);
//echo $save_path.$file_count.'.sql'.'<br/>';
$mysql='';
$files[]=$save_path.$file_count.'.sql';
}
}
if ($values != "" && $i!=50) {
$insert_sql="INSERT INTO `$table_name` (`$items`) VALUES" . rtrim($values, ",") . ";m;o;n;\n\r";
$mysql.=$insert_sql;
}
}
}
if($mysql!=''){
$file_count++;
file_put_contents($save_path.$file_count.'.sql',$mysql.'monxin_sql_end');
//echo $save_path.$file_count.'.sql'.'<br/>';
$mysql='';
$files[]=$save_path.$file_count.'.sql';
}elseif($file_count>0){
//echo $save_path.$file_count.'.sql<hr>';
file_put_contents($save_path.$file_count.'.sql',file_get_contents($save_path.$file_count.'.sql').'monxin_sql_end');
}
$_POST['output_table']=$files;
return true;
}
//本代码基于Monxin 运行
//代码来源:Monxin ./config/functions.php
function output_table($pdo,$save_dir,$program='',$flag=1){
set_time_limit(0);
$mysql='monxin_sql_start';
if($program!=''){
$statments=$pdo->query("show tables like '".$pdo->sys_pre.$program."_%'");
}else{
$statments=$pdo->query("show tables like '".$pdo->sys_pre."%'");
}
$file_count=0;
$save_dir.='/';
$save_dir=str_replace('//','/',$save_dir.'/');
$save_path=$save_dir.date('Y-m-d_H-i',time()).'_'.rand(100,99999).'__';
$files=array();
foreach ($statments as $value) {
$table_name=$value[0];
$mysql.="DROP TABLE IF EXISTS `$table_name`;m;o;n;\n\r";
$table_query=$pdo->query("show create table `$table_name`");
$create_sql=$table_query->fetch();
$mysql.=$create_sql['Create Table'] .";m;o;n;\n\r";
if ($flag != 0) {
$iteams_query=$pdo->query("select * from `$table_name`");
$values="";
$items="";
$i=0;
while ($item_query=$iteams_query->fetch(PDO::FETCH_ASSOC)){
$i++;
$item_names=array_keys($item_query);
$item_names=array_map("addslashes", $item_names);
$items=join('`,`', $item_names);
$item_values=array_values($item_query);
$item_values=array_map("addslashes", $item_values);
$value_string=join("','", $item_values);
$value_string="('" . $value_string . "'),";
$values.="\n" . $value_string;
if($i==50){
$mysql.= "INSERT INTO `$table_name` (`$items`) VALUES" . rtrim($values, ",") . ";m;o;n;\n\r";
$i=0;
$items='';
$values='';
}
if(strlen($mysql)>(1024*1024*10)){
$file_count++;
file_put_contents($save_path.$file_count.'.sql',$mysql);
//echo $save_path.$file_count.'.sql'.'<br/>';
$mysql='';
$files[]=$save_path.$file_count.'.sql';
}
}
if ($values != "" && $i!=50) {
$insert_sql="INSERT INTO `$table_name` (`$items`) VALUES" . rtrim($values, ",") . ";m;o;n;\n\r";
$mysql.=$insert_sql;
}
}
}
if($mysql!=''){
$file_count++;
file_put_contents($save_path.$file_count.'.sql',$mysql.'monxin_sql_end');
//echo $save_path.$file_count.'.sql'.'<br/>';
$mysql='';
$files[]=$save_path.$file_count.'.sql';
}elseif($file_count>0){
//echo $save_path.$file_count.'.sql<hr>';
file_put_contents($save_path.$file_count.'.sql',file_get_contents($save_path.$file_count.'.sql').'monxin_sql_end');
}
$_POST['output_table']=$files;
return true;
}
0 0
- 导出mysql数据表 Monxin专用(PHP代码函数)
- 删除monxin子程序的相关数据表 Monxin专用(PHP代码函数)
- 数据导入mysql Monxin专用(PHP代码函数)
- 修复MYSQL数据库 Monxin专用(PHP代码函数)
- 优化MYSQL数据库 Monxin专用(PHP代码函数)
- 获取monxin所在目录 Monxin专用(PHP代码函数)
- PHP发送短信 Monxin专用(PHP代码函数)
- 操作用户余额 Monxin专用(PHP代码函数)
- 查询可用短信余额 Monxin专用(PHP代码函数)
- 发送邮件 Monxin专用(PHP代码函数)
- 格式化字段 Monxin专用(PHP代码函数)
- 格式化字段为checkbox Monxin专用(PHP代码函数)
- 获取模板所在目录 Monxin专用(PHP代码函数)
- 获取monxin_table.css路径 Monxin专用(PHP代码函数)
- 获取monxin_table.js 路径 Monxin专用(PHP代码函数)
- 获取程序中文名 Monxin专用(PHP代码函数)
- 获取地区名称 Monxin专用(PHP代码函数)
- 获取地区选项ids Monxin专用(PHP代码函数)
- Python开源项目大全
- LeetCode Climbing Stairs
- 用js 过滤脚本的正则
- 解决“Dynamic Web Module 3.0 requires Java 1.6 or newer.”错误
- 将Cocos2dx 3.4 嵌入到MFC中
- 导出mysql数据表 Monxin专用(PHP代码函数)
- android 帮助文档 下载源码
- Mac 系统忘记用户登录秘密
- 人最重要的能力是什么?
- Java实现RSA算法加密和解密的效率问题(问题描述)
- VS2005 中动态链接库引入库的设置方法
- Java面试题集(181-185)
- 发送邮件 Monxin专用(PHP代码函数)
- 人生苦短,我用Python 学习笔记——第三天