Home > php教程 > php手册 > body text

ThinkPHP写数组插入与获取最新插入数据ID实例

WBOY
Release: 2016-06-06 20:17:59
Original
1226 people have browsed it

这篇文章主要介绍了ThinkPHP写数组插入与获取最新插入数据ID的方法,实例讲述了ThinkPHP基于数组操作数据库的方法,具有一定的参考借鉴价值,需要的朋友可以参考下

本文实例讲述了thinkphp写数组插入与获取最新插入数据ID的实现方法。分享给大家供大家参考。具体方法分析如下:

该实例讲述了thinkphp怎么自己写数组插入,,此处是以注册用户为例。

具体实现代码如下:

复制代码 代码如下:

public function insert2(){
 header("Content-Type:text/html; charset=utf-8");
 $Dao = M("User"); // 构建写入的数据数组
 $data["username"] = $_POST["username"];
 $data["password"] = md5($_POST["password"];);
 $data["email"] = $_POST["email"];
 $data["regdate"] = time(); // 写入数据
 if($lastInsId = $Dao->add($data)){  //$lastInsId为最新插入数据的id
 echo "插入数据 id 为:$lastInsId";
 } else {
 $this->error('数据写入错误!');
 }
 }

希望本文所述对大家的ThinkPHP框架程序设计有所帮助。

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 Recommendations
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!