Home > CMS Tutorial > DEDECMS > body text

How to write dedecms: add, delete, modify, check

angryTom
Release: 2019-07-19 10:34:58
Original
2954 people have browsed it

How to write dedecms: add, delete, modify, check

Tips: dedecms common.inc.phpThe code encapsulates the database information and can be imported directly.

Recommended tutorial: dedecms tutorial

##1. Dede database query:

<?php
      require_once (dirname(__FILE__) . "/include/common.inc.php");  //引用数据库连接文件
      if($dsql->IsTable(&#39;dede_test&#39;)){
          //如果存在dede_test表
          //-------------------
          //|    查询一条记录 |
          //|    GetOne()     |
          //-------------------
          //        ↓
          $row = $dsql->GetOne("SELECT * FROM dede_test WHERE id = 3");
          print_r($row);
         $sql = "SELECT * FROM dede_test";
            $dsql->Execute(&#39;me&#39;,$sql);
            while($arr = $dsql->GetArray(&#39;me&#39;))
            {
                echo "id = {$arr[&#39;id&#39;]} ,name = {$arr[&#39;name&#39;]}<br />";
            }
      }
?>
Copy after login

2. Dede delete data

<?php
            $id = 1 ;
            if($id>0){
                $sql = "DELETE FROM dede_test WHERE id=&#39;$id&#39;";
                $dsql->ExecuteNoneQuery($sql);
                ShowMsg("成功删除一条记录内容!","true.php");  //执行成功后跳转到true.php页面
                exit();  
            }else{
                 ShowMsg("参数不对!","text.php");  //跳转到text.php页面
                exit();  
            }
?>
Copy after login

3. dedecms insert data

<?php
       $sql="INSERT INTO dede_test(name,one,two) VALUES ( &#39;$name&#39;,&#39;$one&#39;,&#39;$two&#39;)";
            $dsql->ExecuteNoneQuery($sql);
            $lastInsertID = $dsql->GetLastID();
            ShowMsg("成功增加一条记录内容!","test.php");
?>
Copy after login

4.dedecms modify data

<?php
            $sql="UPDATE dede_test SET name=&#39;$name&#39;,one=&#39;$one&#39;,two=&#39;$two&#39;  WHERE ID = &#39;$id&#39;";
            $dsql->ExecuteNoneQuery($sql);
            $lastInsertID = $dsql->GetLastID();
            ShowMsg("成功修改一条记录内容!","true.php");  //操作成功跳转到true.php
            exit();

?>
Copy after login


The above is the detailed content of How to write dedecms: add, delete, modify, check. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!