dede数据库的常用的操作方法有哪些

在二次开发中会用到dedecms操作数据库的各种方法。

首先,介绍common.inc.php文件

require_once (dirname(__FILE__)。\”/include/common . Inc . PHP \”);

1、获取记录的内容:

$row = $dsql-&gt。GetOne(\”Select * From dede_*其中id = $ aid \”);echo $ row[\’ id \’];

2.输出查询得到的总数:

$row = $dsql-&gt。GetOne(\”选择count(*)作为dd,其中typeid = $ typeid \”);echo $ row[\’ DD \’];//总输出

3.输出几条查询记录

$sql = \”从dede_* \”中选择*;$dsql-&gt。SetQuery($ SQL);//格式化SQL查询语句$ dsql->;execute();//执行SQL操作//执行结果while($ row = $ dsql–>:GetArray()){ echo $ row[\’ id \’];echo $ row[\’ title \’];}//或while输出内容($ row = $ dsql->:GetObject()){ echo $ row->;id;echo $row->标题;{}

4.输出几条查询记录

$dsql-&gt。SetQuery(\”Select id,typename From `dede_arctype `其中reid=0,channeltype=1,ishidden=0,ispart & lt&gt。2按sortrank排序\”);$dsql-&gt。execute();while($ row = $ dsql->;GetObject()){ $ channel ist。= \” { $ 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\’);\”;//插入记录数据库 $dsql->ExecuteNoneQuery($sql);//执行SQL操作 $gid = $dsql->GetLastID();//获取刚刚插入的id$ SQL = \” INSERT INTO ` dede _ member _ flink `(mid,title,url,linktype,imgurl,imgwidth,img heght)VALUES(\”)。$cfg_ml-&gt。M_ID。\”,\’ $title \’,\’ $url \’,\’ $linktype \’,\’ $imgurl \’,\’ $imgwidth \’,\’ $ imgheight \’);\”;//插入记录数据库$ dsql->;executone query($ SQL);//执行SQL操作$ GID = $ dsql->;GetLastID();//获取刚刚插入的id

6.删除记录

$ SQL = \” Delete From dede _ member _ flink其中aid=\’$aid\’ And mid= \’ \”。$cfg_ml-&gt。M_ID。”;”;$dsql-&gt。SetQuery($ SQL);$dsql-&gt。executonequery();//或者使用简化模式$ dsql->:executonequery(\” Delete From dede _ member _ flink其中aid=\’$aid\’ And mid= \’ \”。$cfg_ml-&gt。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);$ up query = \” Update dede _ member _ flink set title = \’ $ title \’,url=\’$url \’,linktype=\’$linktype \’,imgurl=\’$imgurl \’,imgwidth=\’$imgwidth \’,imgheight = \’ $ imgheight \’其中aid=\’$aid\’ And mid= \’ \”。$cfg_ml-&gt。M_ID。”;”;$rs = $dsql-&gt。executone query($ up query);

8.确定获取数据库内容的常用方法

$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 \”失败\”; }$row = $dsql-&gt。GetOne(\” Select * From dede _ money card _ type其中tid = { $ PID } \”;if(!is _ array($ row)){ echo \” failed \”;exit();} $ up query = \” Update dede _ member _ flink set title = \’ $ title \’,url=\’$url \’,linktype=\’$linktype \’,imgurl=\’$imgurl \’,imgwidth=\’$imgwidth \’,imgheight = \’ $ imgheight \’其中aid=\’$aid\’ And mid= \’ \”。$cfg_ml-&gt。M_ID。”;”;$rs = $dsql-&gt。executone query($ up query);if($ RS){ echo \” success \”;}else{ echo \”失败\”;{}

9.得到总数

$ dsql = new DeDeskL(false);$dsql-&gt。set query(\” Select * from ` dede _ admin `其中userid=\’$userid \’或uname = \’ $ uname \’);$dsql-&gt。execute();$ns = $dsql-&gt。GetTotalRow();关闭数据库$ dsql->:Close();

转载:非常欢迎与个人站长或朋友圈分享,但请说明文章出处& ldquo李SEO博客;。

原地址:http://www . alitaoho . com/cmsjaaocheng/zhimgjaaocheng/1916 . html。

为您推荐

发表评论

电子邮件地址不会被公开。