数据查询源码php php数据库查询语句( 二 )


var $mFp;
function fileOperation() {
}
function openFile($mode='w'){
if(empty($this-fileName)){
$this-setTimeFileName();
}
if (empty($this-extendName)){
$this-setExtendName();
}
$fp=fopen($this-mPath.'/'.$this-fileName.'.'.$this-extendName,$mode);
if($fp){
$this-mFp=$fp;
}else{
return 0;
}
}
function closeFile(){
return fclose($this-mFp);
}
function setTimeFileName($type='Ymd'){
if(!empty($type)){
$this-fileName=$type;
}else{
$this-fileName=time();
}
}
function setExtendName($extend='txt'){
if(!empty($extend)){
$this-extendName=$extend;
}else{
$this-extendName='.csv';
}
}
function setPath($path='./'){
$this-mPath=$path;
}
}
xlsHelper.php
****************************************************
require_once 'fileOperation.php';
class xlsHelper extends fileOperation{//具体实现子类
var $mSpace = '';
var $mHead;
var $mBody='';
function addHeader($head=array()){
$this-mHead='table width="500" border="1" align="center" cellpadding="5"tr';
if (is_array($head)){
foreach($head as $hd){
$this-mHead.='th bgcolor="#A5A0DE"'.$hd.'/th';
}
}
$this-mHead.='/tr';
}
function addBodyData($body=array()){
if(is_array($body)){
for($i=0;$icount($body);$i++){
$childBody=$body[$i];
$this-mBody.='tr';
$this-mSpace = 'td align="center"';
for($j=0;$jcount($childBody);$j++){
$this-mBody.=$this-mSpace.$childBody[$j].'/td';
}
$this-mBody.="/tr";
}
}
$this-mBody.='/table';
}
function _construct(){
}
function writeCSVDate(){
return fwrite($this-mFp,$this-mHead.mb_convert_encoding($this-mBody,'sjis','sjis'));
}
function setSpace($type=','){
$this-mSpace=$type;
}
}
test.php
****************************************************
$xls=new xlsHelper();
$xls-fileName='xxx';//设置生成文件的文件名
$xls-extendName='xls';//文件扩展名
$xls-mPath='./';//文件保存路径
$headerarr=array('姓名','年龄','邮箱');//头部字段名
$xls-addHeader($headerarr);
$datasarr=array(//注意:此处的二维数组一定要是数字索引
array('yht',20,'yht@163.com'),
array('ktv009',23,'ktv009@sina.com'),
);
$xls-addBodyData($datasarr);
$xls-openFile('w');
if($xls-writeCSVDate())echo "script language='javascript'生成文件成功/script";
elseecho ""script language='javascript'无法生成文件/script";
如何查看php页面的源代码PHP页面的源代码是看不见的
因为你看到的网页已经是PHP经过服务器解析后输出的内容了!
PHP是一门弱类型的服务器脚本语言,
下面是你访问一个url后经过的一些主要步骤:
你向服务器请求一个页面,服务器只认识静态HTML网页,不认识PHP于是,让PHP处理(这里可以是各种操作,比如:查询数据库),PHP处理完成后再把结果返回给服务器呈现到浏览器
关于数据查询源码php和php数据库查询语句的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站 。

推荐阅读