|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
php manual(PHP手册)肯定是要从网上下载一个的,它很权威,也很全面,我自己认为它是一本很好的参考书,但是不适合新手当教材使用。 前些世界载了adodb,想用adodb连access数据库,后来连是连上了,不外不克不及更新和拔出纪录,也不晓得为何到如今还没人给我回覆谁人忧?的成绩,后来就保持了adodb,利用php本人的odbc,然而利用很不便利,就写下了上面这些函数,还没有封装成类,但愿可以为有一样成绩的伴侣一些匡助
<?php
/*
* @ access class
* insert,update,delete record
* version 1.0
* date 2005.6
* power by Samsun Manzalo (34n 猪八戒)
*/
//=====================================================
// insert record
// 拔出纪录
//=====================================================
function insRd($table,$field){
$connstr = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=database/email.mdb";
$connid = @odbc_connect($connstr,"","",SQL_CUR_USE_ODBC ) or die ("数据库毗连毛病!");
$tmpA = explode(',',$field);
$ins = '';
for($i=0;$i<count($tmpA);$i++){
$ins.= "'".$_POST[$tmpA[$i]]."',";
}
$ins = substr($ins,0,-1);
$sql = "INSERT INTO ".$table." (".$field.") VALUES (".$ins.")";
//echo $sql;exit;
$query = @odbc_do($connid,$sql);
}
//=======================================================================
// get one record detail
// 获得当笔记录具体信息
//=======================================================================
function getInfo($table,$field,$id,$colnum){
$connstr = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=database/email.mdb";
$connid = @odbc_connect($connstr,"","",SQL_CUR_USE_ODBC ) or die ("数据库毗连毛病!");
$sql = "select * from ".$table." where ".$field."=".$id;
$query = @odbc_do($connid,$sql);
if(odbc_fetch_row($query)){
for($i=0;$i<$colnum;$i++){
$info[$i] = odbc_result($query,$i+1);
}
}
return $info;
}
//=================================================================
// get record list
// 获得纪录列表
//=================================================================
function getList($table,$field,$colnum,$condition,$sort="order by id desc"){
$connstr = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=database/email.mdb";
$connid = @odbc_connect($connstr,"","",SQL_CUR_USE_ODBC ) or die ("数据库毗连毛病!");
$sql = "select * from ".$table." ".$condition." ".$sort;
$query = @odbc_do($connid,$sql);
//echo $sql."<br>";
$i = 0;
while(odbc_fetch_row($query)){
$rdList[$i] = getInfo($table,$field,odbc_result($query,1),$colnum);
$i++;
}
return $rdList;
}
//=============================================================
// get record list condition
// 获得纪录列表
//=============================================================
function getFieldList($table,$field,$fieldnum,$condition="",$sort=""){
$connstr = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=database/email.mdb";
$connid = @odbc_connect($connstr,"","",SQL_CUR_USE_ODBC ) or die ("数据库毗连毛病!");
$sql = "select ".$field." from ".$table." ".$condition." ".$sort;
$query = @odbc_do($connid,$sql);
//echo $sql."<br>";
$i = 0;
while(odbc_fetch_row($query)){
for($j=0;$j<$fieldnum;$j++){
$info[$j] = odbc_result($query,$j+1);
}
$rdList[$i] = $info;
$i++;
}
return $rdList;
}
//======================================================================
// update record
// 更新纪录
//======================================================================
function updateInfo($table,$field,$id,$set){
$connstr = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=database/email.mdb";
$connid = @odbc_connect($connstr,"","",SQL_CUR_USE_ODBC ) or die ("数据库毗连毛病!");
$sql = "update ".$table." set ".$set." where ".$field."=".$id;
$query = @odbc_do($connid,$sql);
}
//=====================================================================
// record delete
// 删除纪录
//=====================================================================
function delRd($table,$field,$id){
$connstr = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=database/email.mdb";
$connid = @odbc_connect($connstr,"","",SQL_CUR_USE_ODBC ) or die ("数据库毗连毛病!");
$sql = "delete from ".$table." where ".$field."=".$id;
$query = @odbc_do($connid,$sql);
}
//=====================================================================
// record delete cat
// 删除纪录(前提)
//=====================================================================
function delOrRd($table,$condition){
$connstr = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=database/email.mdb";
$connid = @odbc_connect($connstr,"","",SQL_CUR_USE_ODBC ) or die ("数据库毗连毛病!");
$sql = "delete from ".$table." where ".$condition;
$query = @odbc_do($connid,$sql);
}
//=========================================================================
// count record
// 获得纪录数
//=========================================================================
function countRd($table,$condition=""){
$connstr = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=database/email.mdb";
$connid = @odbc_connect($connstr,"","",SQL_CUR_USE_ODBC ) or die ("数据库毗连毛病!");
$sql = "select count(*) as num from ".$table." ".$condition;
$query = @odbc_do($connid,$sql);
odbc_fetch_row($query);
$num = odbc_result($query,1);
return $num;
}
?>
也许您在学习PHP的时候只想尽快的开发一个网站,也就会想我做网站,干嘛要学什么网页这些小儿科?不难看出,眼高手低的新手不在少数,这种思想无疑于建造空中楼阁,你不建地基,何来的房顶呢? |
|