提示:dedecms common.inc.php代码中封装了数据库信息,直接引入即可。
1、dede数据库查询:<?php
require_once (dirname(__FILE__) . "/include/common.inc.php"); //引用数据库连接文件
if($dsql->IsTable('dede_test')){
//如果存在dede_test表
//-------------------
//| 查询一条记录 |
//| GetOne() |
//-------------------
// ↓
$row = $dsql->GetOne("SELECT * FROM dede_test WHERE id = 3");
print_r($row);
$sql = "SELECT * FROM dede_test";
$dsql->Execute('me',$sql);
while($arr = $dsql->GetArray('me'))
{
echo "id = {$arr['id']} ,name = {$arr['name']}
";
}
}
?>
2、dede删除数据<?php
$id = 1 ;
if($id>0){
$sql = "DELETE FROM dede_test WHERE id='$id'";
$dsql->ExecuteNoneQuery($sql);
ShowMsg("成功删除一条记录内容!","true.php"); //执行成功后跳转到true.php页面
exit();
}else{
ShowMsg("参数不对!","text.php"); //跳转到text.php页面
exit();
}
?>
3、dedecms插入数据<?php
$sql="INSERT INTO dede_test(name,one,two) VALUES ( '$name','$one','$two')";
$dsql->ExecuteNoneQuery($sql);
$lastInsertID = $dsql->GetLastID();
ShowMsg("成功增加一条记录内容!","test.php");
?>
4、dedecms修改数据<?php
$sql="UPDATE dede_test SET name='$name',one='$one',two='$two' WHERE ID = '$id'";
$dsql->ExecuteNoneQuery($sql);
$lastInsertID = $dsql->GetLastID();
ShowMsg("成功修改一条记录内容!","true.php"); //操作成功跳转到true.php
exit();
?>