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

from:http://www.xland.com.cn/article/7/81/0804/28778.htm

本类实现:

数据库信息导出: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');

//输出结果

3导出excel和word

PHP代码:

以下是代码片段:

$db=new db();

//toExcel

$map=array('No','Name','Email','Age');//表头

$db->toExcel('test', $map,'档案');

//导出word表格

// $db->toWord('test', $map,'档案');

//效果如下图

excel.JPG (27.04 KB)

2008-4-19 11:09

PHP代码:

以下是代码片段:

class Db

{

var  $conn;

function Db( $host="localhost", $user="root", $pass="", $db="mytest")

{

if(! $this->conn=mysql_connect( $host, $user, $pass))

die("can't connect to mysql sever");

mysql_select_db( $db,&ensp

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值