天天躁日日躁狠狠躁AV麻豆-天天躁人人躁人人躁狂躁-天天澡夜夜澡人人澡-天天影视香色欲综合网-国产成人女人在线视频观看-国产成人女人视频在线观看

一個基于PDO的數(shù)據(jù)庫操作類

百度之后決定使用PDO,至于為什么選擇PDO,這里就不再多說,大家自己去百度下就能明白。
既然要換,那最基本就需要有個常用的數(shù)據(jù)庫操作類,也就是所謂的增刪改查等,昨晚搗騰了一晚,大致弄出了個雛形,以下就是代碼,希望大家能給出點意見。
復(fù)制代碼 代碼如下:
<?php
/*
作者:胡睿
日期:2011/03/19
電郵:hooray0905@foxmail.com
20110319
常用數(shù)據(jù)庫操作,如:增刪改查,獲取單條記錄、多條記錄,返回最新一條插入記錄id,返回操作記錄行數(shù)等
*/
/*
參數(shù)說明
int $debug 是否開啟調(diào)試,開啟則輸出sql語句
int $getcount 是否記數(shù),返回值為行數(shù)
int $getrow 是否返回值單條記錄
string $table 數(shù)據(jù)庫表
string $fields 需要查詢的數(shù)據(jù)庫字段,允許為空,默認為查找全部
string $sqlwhere 查詢條件,允許為空
string $orderby 排序,允許為空,默認為id倒序
*/
function hrSelect($debug, $getcount, $getrow, $table, $fields="*", $sqlwhere="", $orderby="id desc"){
global $pdo;
if($debug){
if($getcount){
echo "select count(*) from $table where 1=1 $sqlwhere order by $orderby";
}else{
echo "select $fields from $table where 1=1 $sqlwhere order by $orderby";
}
exit;
}else{
if($getcount){
$rs = $pdo->query("select count(*) from $table where 1=1 $sqlwhere order by $orderby");
return $rs->fetchColumn();
}elseif($getrow){
$rs = $pdo->query("select $fields from $table where 1=1 $sqlwhere order by $orderby");
return $rs->fetch();
}else{
$rs = $pdo->query("select $fields from $table where 1=1 $sqlwhere order by $orderby");
return $rs->fetchAll();
}
}
}
/*
參數(shù)說明
int $debug 是否開啟調(diào)試,開啟則輸出sql語句
int $execrow 是否開啟返回執(zhí)行條目數(shù)
int $lastinsertid 是否開啟返回最后一條插入記錄id
string $table 數(shù)據(jù)庫表
string $fields 需要插入數(shù)據(jù)庫的字段
string $values 需要插入數(shù)據(jù)庫的信息,必須與$fields一一對應(yīng)
*/
function hrInsert($debug, $execrow, $lastinsertid, $table, $fields, $values){
global $pdo;
if($debug){
echo "insert into $table ($fields) values ($values)";
exit;
}elseif($execrow){
return $pdo->exec("insert into $table ($fields) values ($values)");
}elseif($lastinsertid){
return $pdo->lastInsertId("insert into $table ($fields) values ($values)");
}else{
$pdo->query("insert into $table ($fields) values ($values)");
}
}
/*
參數(shù)說明
int $debug 是否開啟調(diào)試,開啟則輸出sql語句
int $execrow 是否開啟執(zhí)行并返回條目數(shù)
string $table 數(shù)據(jù)庫表
string $set 需要更新的字段及內(nèi)容,格式:a='abc',b=2,c='2010-10-10 10:10:10'
string $sqlwhere 修改條件,允許為空
*/
function hrUpdate($debug, $execrow, $table, $set, $sqlwhere=""){
global $pdo;
if($debug){
echo "update $table set $set where 1=1 $sqlwhere";
exit;
}elseif($execrow){
return $pdo->exec("update $table set $set where 1=1 $sqlwhere");
}else{
$pdo->query("update $table set $set where 1=1 $sqlwhere");
}
}
/*
參數(shù)說明
int $debug 是否開啟調(diào)試,開啟則輸出sql語句
int $execrow 是否開啟返回執(zhí)行條目數(shù)
string $table 數(shù)據(jù)庫表
string $sqlwhere 刪除條件,允許為空
*/
function hrDelete($debug, $execrow, $table, $sqlwhere=""){
global $pdo;
if($debug){
echo "delete from $table where 1=1 $sqlwhere";
exit;
}elseif($execrow){
return $pdo->exec("delete from $table where 1=1 $sqlwhere");
}else{
$pdo->query("delete from $table where 1=1 $sqlwhere");
}
}
?>

參數(shù)的注釋都寫的很清楚,如果有人需要,不清楚使用方法可以直接問我。

php技術(shù)一個基于PDO的數(shù)據(jù)庫操作類,轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 大稥焦伊人一本dao 大香伊人中文字幕精品 | 欧式午夜理伦三级在线观看 | 乱亲女H秽乱长久久久 | 亚洲欧美一区二区久久 | 教室里的激情电影 | 别停好爽好深好大好舒服视频 | 国产一区二区不卡老阿姨 | 99久久国产综合色 | 极品少妇伦理一区二区 | 日本电影免费久久精品 | 小玲被公扒开腿 | 奶好大下面流了好多水水 | 国产在线亚洲精品观看不卡 | 伊人久久电影网 | 日韩精品卡1卡2三卡四卡乱码 | 国产手机在线亚洲精品观看 | 97无码欧美熟妇人妻蜜 | 好男人视频免费高清在线观看www | 日日摸夜夜嗷嗷叫日日拍 | 91精品一区二区三区在线观看 | 父亲在线日本综艺免费观看全集 | 少妇两个奶头喷出奶水了怎么办 | 中文视频在线观看 | 纯肉高H种马艳遇风流多 | 久久无码AV亚洲精品色午夜 | 一本久道久久综合婷婷五月 | 国产中文字幕在线 | 伊人青青草原 | 俄罗斯美女性生活 | 牲高潮99爽久久久久777 | 久久国内精品视频 | 世界上第一个得抑郁症的人是谁 | 欧美另类极品videosbest | 欧美嫩freexxxhddvd | 无人区国产片 | 污污内射久久一区二区欧美日韩 | 国产成人精品免费视频大 | 父亲在线日本综艺免费观看全集 | 大学生第一次破苞疼哭了 | 无套日出白浆在线播放 | 2021乱码精品公司 |