ThinkPHP3.2.3 - 常用MySql语句(增删改查)
add($data) 将一个数据保存到数据库
<form action="/tp/index.php/Home/User/adda" method="post" >
姓名:<input name="name" type="text" /><br>
年龄:<input name="age" type="text" /><br>
<input type="submit" value="提交" />
</form>
public function adda(){
$data["name"] = $_POST["name"];
$data["age"] = $_POST["age"];
$UserModel = new UserModel();
$result = $UserModel->add($data);
if($result){
$this->success("提交成功","/tp/index.php/Home/User/Index");
}else{
$this->error("保存失败");
}
}addAll (二维数组) 将多个数据保存到数据库
save($data) 将数据更新到指定一个记录中
select() 查询符合条件的多行,以二维数据形式出现
<table bgcolor="#848484" border="1">
<tr>
<th>ID</th>
<th>姓名</th>
<th>年龄</th>
</tr>
<?php
foreach($rows as $a):
?>
<tr>
<td><?php echo $a["id"];?></td>
<td><?php echo $a["name"];?></td>
<td><?php echo $a["age"];?></td>
</tr>
<?php endForeach; ?>
</table>
<pre name="code" class="php">class UserController extends Controller {
public function index(){
$UserModel = new UserModel(); //引入模型
$rows = $UserModel->select(); //查询
$this->assign("rows",$rows); //输出到模板
$this->display(); //调用模式
}
}find() 查询符合条件的一行,以一维数组形式出现
声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。
