dedecms操作數(shù)據(jù)庫(kù)的各類方法,二次開(kāi)發(fā)都會(huì)用到的。
首先,引入common.inc.php文件
require_once (dirname(__FILE__) . "/include/common.inc.php");
1、獲取一條記錄的內(nèi)容:
$row = $dsql->GetOne("Select * From dede_* where id = $aid"); echo $row['id'];
2、將查詢獲取總數(shù)輸出:
$row = $dsql->GetOne("select count(*) as dd where typeid = $typeid"); echo $row['dd'];//輸出總數(shù)
3、將查詢的若干條記錄輸出
$sql = "Select * from dede_*"; $dsql->SetQuery($sql);//將SQL查詢語(yǔ)句格式化 $dsql->Execute();//執(zhí)行SQL操作 //通過(guò)循環(huán)輸出執(zhí)行查詢中的結(jié)果 while($row = $dsql->GetArray()){ echo $row['id']; echo $row['title']; } //或者采取這種方式輸出內(nèi)容 while($row = $dsql->GetObject()){ echo $row->id; echo $row->Title; }
4、將查詢的若干條記錄輸出
$dsql->SetQuery("Select id,typename From `dede_arctype` where reid=0 And channeltype=1 And ishidden=0 And ispart<>2 order by sortrank"); $dsql->Execute(); while($row=$dsql->GetObject()) { $channellist .= "{$row->typename} "; echo $row->id; }
5、插入一條記錄
$sql = " INSERT INTO `dede_member_flink`(mid,title,url,linktype,imgurl,imgwidth,imgheight) VALUES(".$cfg_ml->M_ID.",'$title','$url','$linktype','$imgurl','$imgwidth','$imgheight');";//插入記錄數(shù)據(jù)庫(kù) $dsql->ExecuteNoneQuery($sql);//執(zhí)行SQL操作 $gid = $dsql->GetLastID();//獲取剛剛插入的id
6、刪除一條記錄
$sql = "Delete From dede_member_flink where aid='$aid' And mid='".$cfg_ml->M_ID."';"; $dsql->SetQuery($sql); $dsql->ExecNoneQuery(); //或者使用簡(jiǎn)化模式 $dsql->ExecNoneQuery("Delete From dede_member_flink where aid='$aid' And mid='".$cfg_ml->M_ID."';");
7、更新一條記錄
$upquery = " Update dede_member_flink set title='$title',url='$url',linktype='$linktype', imgurl='$imgurl',imgwidth='$imgwidth',imgheight='$imgheight' where aid='$aid' And mid='".$cfg_ml->M_ID."'; "; $rs = $dsql->ExecuteNoneQuery($upquery);
8、判斷獲取數(shù)據(jù)庫(kù)內(nèi)容的常用方法
$row = $dsql->GetOne("Select * From dede_moneycard_type where tid={$pid}"); if(!is_array($row)){ echo "失敗"; exit(); } $upquery = " Update dede_member_flink set title='$title',url='$url',linktype='$linktype', imgurl='$imgurl',imgwidth='$imgwidth',imgheight='$imgheight' where aid='$aid' And mid='".$cfg_ml->M_ID."'; "; $rs = $dsql->ExecuteNoneQuery($upquery); if($rs){ echo "成功"; }else{ echo "失敗"; }
9、獲取總數(shù)
$dsql = new DedeSql(false); $dsql->SetQuery("Select * from `dede_admin` where userid='$userid' Or uname='$uname'"); $dsql->Execute(); $ns = $dsql->GetTotalRow(); 關(guān)閉數(shù)據(jù)庫(kù) $dsql->Close();
我們專注高端建站,小程序開(kāi)發(fā)、軟件系統(tǒng)定制開(kāi)發(fā)、BUG修復(fù)、物聯(lián)網(wǎng)開(kāi)發(fā)、各類API接口對(duì)接開(kāi)發(fā)等。十余年開(kāi)發(fā)經(jīng)驗(yàn),每一個(gè)項(xiàng)目承諾做到滿意為止,多一次對(duì)比,一定讓您多一份收獲!