dedecms 增删改查操作总结。

<?php
require_once (dirname(FILE) . "/include/common.inc.php");
print_r($dsql);

    //DedeSql Object ( [linkID] => [dbHost] => [dbUser] => [dbPwd] => [dbName] => [dbPrefix] => [result] => [queryString] => [parameters] => [isClose] => [safeCheck] => 1 [recordLog] => [isInit] => [pconnect] => )

    //这个就说明我们已经成功连接数据库了,[dbHost],[dbUser]...这些都是数据库的相关信息,也就是我们保存在配置文件中的\data\common.inc.php内容,引入数据库类的时候,默认就被创建了$dsql或者$db,所以直接引入配置文件就可以了.

    //检查数据库表是否存在
    if($dsql->IsTable('dede_area')){
        echo 1;
    }else{
        echo 2;
    }

    echo "
"; echo "
"; echo "
"; //获得一行数据 $row = $dsql->GetOne("SELECT * FROM dede_area WHERE id=3"); print_r($row); echo "
"; echo "
"; echo "
"; //这里我们用了$dsql类的2个方法,IsTable()以及GetOne(),IsTable先来判断这个表是否存在,如果存在我们就继续执行,他返回的是一个bool值,如果存在为true否则就为false. //获得一个数组 $rowarr = $dsql->GetArray("SELECT * FROM dede_area WHERE id=3"); print_r($rowarr); echo "
"; echo "
"; echo "
"; //查询数据 $rsrow = $dsql->GetOne("SELECT * FROM dede_area WHERE id=3"); print_r($rsrow); //删除数据 $id = 1; if($id > 0){ $sql = "delete * from dede_arey where id = $id"; $dsql->ExecuteNoneQuery($sql); ShowMsg("删除成功",index.php); exit(); }else{ ShowMsg("删除失败","index.php"); exit(); } //插入 $sql = "insert into dede_area ("id","name","why") value ("111","222","333")"; $dsql -> ExecutNoneQuery($sql); ShowMsg("插入成功",index.php); exit(); //修改 $sql="UPDATE dede_test SET name='$name',one='$one',two='$two' WHERE ID = '$id'"; $dsql->ExecuteNoneQuery($sql); $lastInsertID = $dsql->GetLastID(); ShowMsg("成功修改一条记录内容!","true.php"); //操作成 exit();

发表评论

邮箱地址不会被公开。