thinkphp adding Data Add () method

Source: Internet
Author: User

The Thinkphpz built-in Add () method is used to add data to a database table, equivalent to the INSERT into behavior in SQL
Adding the Data add method is the implementation of create in curd (Create,update,read,delete/Create, modify, read, delete), thinkphp supports writing data to the data table in a normal array and object-oriented manner.
Insert to write data to the data table in a normal array
$insert [' user_id ']= $my [' user_id '];
$insert [' Content_body ']= $content;
$insert [' Posttime ']=time ();
$insert [' Replyid ']= $sid;
$insert [' type ']= $type;
$insertid = $this->add ($insert);
Because the file is in contentModel.class.php, $this<=>d ("Content")
Add () method if the data record is added successfully, the new data record primary key is returned, which can be directly obtained

/*********** writes data to a data table as an object and does not need to pass parameters when the Add method is called to write data *************/
Public Function Insert () {
Header ("content-type:text/html; Charset=utf-8 ");
$Dao = M ("User"); Instantiating a model class
Assigning values to data Objects
$Dao->username = "Xiao Wang";
$Dao->password = MD5 ("123456");
$Dao->email = "[email protected]";
$Dao->regdate = time ();
Write Data
if ($lastInsId = $Dao->add ()) {
echo "Insert Data ID: $lastInsId";
} else {
$this->error (' Data write Error! ‘);
} }

thinkphp adding Data Add () method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.