php数据库导出类 导出JSON,XML,WORD,EXCEL

作者:未知  来源:网络  【打印此文】【
 本类实现:

  数据库信息导出:word,excel,json,xml,sql
  数据库恢复:从sql,从文件

具体用法:

首先新建测试用数据库mytest,然后在里面建张表

PHP代码:

以下是代码片段:
-- 
-- 表的结构 `test`
-- 
CREATE TABLE `test` (
  `id` int(11) NOT NULL auto_increment,
  `name` varchar(100) NOT NULL,
  `email` varchar(200) NOT NULL,
  `age` int(3) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ;
-- 
-- 导出表中的数据 `test`
-- 
INSERT INTO `test` (`id`, `name`, `email`, `age`) VALUES 
(1, 'pjq518', [email=]'pjq518@126.com'[/email], 22),
(2, 'xiaoyu', [email=]'xiaoyu@126.com'[/email], 21);


1.导出ext能方便调用的json

PHP代码:

以下是代码片段:
 $db=new db();
echo  $db->toExtJson('test');

//输出结果为
//{'totalCount':'2','rows':[{'id':'1','name':'pjq518','email':'pjq518@126.com','age':'22'},{'id':'2','name':'xiaoyu','email':'xiaoyu@126.com','age':'21'}]}


toExtJson( $table, $start="0", $limit="10", $cons="")有4个参数, $table为表名, $cons为条件,可以为string或array
2导出xml

PHP代码:

以下是代码片段:
 $db=new db();
echo  $db->toExtXml('test');


//输出结果
seover="attachimginfo(this, 'attach_19823', 1);attachimg(this, 'mouseover')" onclick="{window.open('/up/20080421/2008042114551165.jpg');}" onmouseout="attachimginfo(this, 'attach_19823', 0, event)" alt="" src="/Article/UploadFiles/200805/20080503101147217.jpg" onload="if(this.width>500) {this.resized=true; this.width=500;}" border=0>
3导出excel和word

PHP代码:

以下是代码片段:
 $db=new db();
//toExcel
 $map=array('No','Name','Email','Age');//表头
 $db->toExcel('test', $map,'档案');
//导出word表格
// $db->toWord('test', $map,'档案');


//效果如下图

[1] [2] 下页  




久尚整理     更多关于php数据库导出类 导出JSON,XML,WORD,EXCEL 的文章

{$Title}
搜索:

CSS样式表制作文字

不安装和修改文件

周付联盟推荐第九

QQ免费电子密保卡

QQ邮箱再更新 优化