Home  >  Article  >  Backend Development  >  ThinkPHP写数组插入与获取最新插入数据ID实例_php实例

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

WBOY
WBOYOriginal
2016-06-07 17:15:40901browse

本文实例讲述了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框架程序设计有所帮助。

Statement:
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