php編寫的ACCESS處理類_PHP教程
教程Tag:暫無Tag,歡迎添加,賺取U幣!
推薦:解析基于MVC的輕量級(jí)PHP框架做WEB開發(fā)已有一年,每次都寫重復(fù)的東西, 因此,想自己寫一下框架,以后開發(fā)方便. 本人之前學(xué)習(xí)asp.NET兩年,JSP半年,可是后來因?yàn)楣ぷ鞯脑蕮Q成PHP.其實(shí)很不喜歡PHP的語法.還有PHP的函數(shù)名,每回都忘記..還是喜歡C#和JAVA的語法,哈...不過PHP有PHP的優(yōu)點(diǎn),不像AS
在做項(xiàng)目中要用到ACCESS數(shù)據(jù)庫,所以就寫了一個(gè)ACCESS處理類.函數(shù)名跟ADODB類一樣.
<?php
/*
*ACCESS數(shù)據(jù)庫操作類
*2008-3-26
*LIQUAN
*dsn = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=".PATH_ROOT."databasedata.mdb";
*conn=new Access();
*conn->Connnect(dsn);
*conn->GetArray("select * from test");
*/
class Access
{
var conn;
var fieldsName;
function Access()
{
}
//connection
function Connect(dsn)
{
this->conn = new COM("ADODB.Connection") or die("Cannot start ADO");
this->conn->Open(dsn);
}
//返回一個(gè)
function GetOne(sql)
{
rs = this->conn->Execute(sql);
while (!rs->EOF)
{
value=rs->Fields(0)->value;
rs->MoveNext();
}
rs->Close();
rs=null;
if(!empty(value))
{
return value;
}
else
{
return "";
}
unset(value);
}
//返回大數(shù)組
function GetArray(sql)
{
rs = this->conn->Execute(sql);
num_columns = rs->Fields->Count();
rowcount = 0;
while (!rs->EOF)
{
for (i=0; i < num_columns; i++)
{
fieldName[rowcount][rs->Fields(i)->name]= rs->Fields(i)->value;
}
rowcount++;
rs->MoveNext();
}
rs->Close();
rs=null;
if(!empty(fieldName))
{
return fieldName;
}
else
{
return "";
}
unset(fieldName);
}
//返回小數(shù)組
function GetRow(sql)
{
rs = this->conn->Execute(sql);
num_columns = rs->Fields->Count();
while (!rs->EOF)
{
for (i=0; i < num_columns; i++)
{
fieldName[rs->Fields(i)->name]=rs->Fields(i)->value;
}
rs->MoveNext();
}
rs->Close();
rs=null;
if(!empty(fieldName))
{
return fieldName;
}
else
{
return "";
}
unset(fieldName);
}
//execute SQL
function Execute(sql)
{
if(this->conn->Execute(sql))
{
return true;
}
else
{
return false;
}
}
function Close()
{
this->conn->Close();
}
function __destruct()
{
// this->conn->Close();
}
}
?>
/*
*ACCESS數(shù)據(jù)庫操作類
*2008-3-26
*LIQUAN
*dsn = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=".PATH_ROOT."databasedata.mdb";
*conn=new Access();
*conn->Connnect(dsn);
*conn->GetArray("select * from test");
*/
class Access
{
var conn;
var fieldsName;
function Access()
{
}
//connection
function Connect(dsn)
{
this->conn = new COM("ADODB.Connection") or die("Cannot start ADO");
this->conn->Open(dsn);
}
//返回一個(gè)
function GetOne(sql)
{
rs = this->conn->Execute(sql);
while (!rs->EOF)
{
value=rs->Fields(0)->value;
rs->MoveNext();
}
rs->Close();
rs=null;
if(!empty(value))
{
return value;
}
else
{
return "";
}
unset(value);
}
//返回大數(shù)組
function GetArray(sql)
{
rs = this->conn->Execute(sql);
num_columns = rs->Fields->Count();
rowcount = 0;
while (!rs->EOF)
{
for (i=0; i < num_columns; i++)
{
fieldName[rowcount][rs->Fields(i)->name]= rs->Fields(i)->value;
}
rowcount++;
rs->MoveNext();
}
rs->Close();
rs=null;
if(!empty(fieldName))
{
return fieldName;
}
else
{
return "";
}
unset(fieldName);
}
//返回小數(shù)組
function GetRow(sql)
{
rs = this->conn->Execute(sql);
num_columns = rs->Fields->Count();
while (!rs->EOF)
{
for (i=0; i < num_columns; i++)
{
fieldName[rs->Fields(i)->name]=rs->Fields(i)->value;
}
rs->MoveNext();
}
rs->Close();
rs=null;
if(!empty(fieldName))
{
return fieldName;
}
else
{
return "";
}
unset(fieldName);
}
//execute SQL
function Execute(sql)
{
if(this->conn->Execute(sql))
{
return true;
}
else
{
return false;
}
}
function Close()
{
this->conn->Close();
}
function __destruct()
{
// this->conn->Close();
}
}
?>
分享:php如何實(shí)現(xiàn)報(bào)表類原創(chuàng)內(nèi)容....實(shí)現(xiàn)曲線圖,餅圖,柱形圖. 轉(zhuǎn)貼請(qǐng)注明出處, http://blog.csdn.net/liq330 效果圖: 原代碼如下: ?php class ImageReport { var Image;//圖片對(duì)像 var ImageName;//報(bào)表名稱 var ImageType;//報(bào)表類型 var ImageWidth;//圖片寬 var ImageHeight;//
相關(guān)PHP教程:
- PHPNOW安裝Memcached擴(kuò)展方法詳解
- php記錄頁面代碼執(zhí)行時(shí)間
- PHP中獎(jiǎng)概率的抽獎(jiǎng)算法程序代碼
- apache設(shè)置靜態(tài)文件緩存方法介紹
- php對(duì)圖像的各種處理函數(shù)代碼小結(jié)
- PHP 關(guān)于訪問控制的和運(yùn)算符優(yōu)先級(jí)介紹
- 關(guān)于PHP語言構(gòu)造器介紹
- php/js獲取客戶端mac地址的實(shí)現(xiàn)代碼
- php5.5新數(shù)組函數(shù)array_column使用
- PHP preg_match的匹配多國語言的技巧
- php 中序列化和json使用介紹
- php采集文章中的圖片獲取替換到本地
- 相關(guān)鏈接:
- 教程說明:
PHP教程-php編寫的ACCESS處理類
。