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