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´úÂë:
ÒÔÏÂÊÇ´úÂëƬ¶Î£º
<?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