<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>织梦数据库操作测试</title>
</head>
<body>
<h1>织梦数据库操作测试</h1>
<hr />
<?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");
echo "查询id=3的记录:<br />显示结果:";
echo $row['name'];
//| 查询多条记录 |
//| Execute() |
// ↓
echo "<hr />查询dede_test表中的所有记录:<br />显示结果:<br />";
$sql = "SELECT * FROM dede_test";
$dsql->Execute('me',$sql);
while($arr = $dsql->GetArray('me'))
{
echo "id = {$arr['id']} ,name = {$arr['name']}<br />";
}
}
?>
<hr />
添加记录
<hr />
用于提交数据的表单:<br />
<form action="test.php" type="post">
<input type="hidden" name="dopost" value="save">
名称:<input type="text" name="name" value="">
<input name="提交" type="submit" value="提交">
</form>
<?php
//-------------------
//| 表单处理过程 |
//| Save() |
//-------------------
// ↓
empty($dopost)? "" : $dopost;
if($dopost == "save"){
//如果执行插入操作
$sql = "INSERT INTO dede_test (name) VALUES ('{$name}')";
$dsql->ExecuteNoneQuery($sql); //执行这个插入语句
echo "获取值".$name;
echo "<br/>执行的语句<br/>".$sql;
$lastInsertID = $dsql->GetLastID(); //获取插入后的最后的ID,然后再传给下一个页面
echo "<br/>最后的".$lastInsertID;
}?>
</body>
</html>