ThinkPHP database problems if I want to associate two tables, I can use join to integrate the content of the two tables for query, but I want to put the content of a form, how can I insert data to two different tables based on the content? Give me a thought. thank you !! ------ Solution ------------------ join array can solve ------ solution ---- thinkPHP database problems
If I want to associate two tables, I can use join to integrate the content of the two tables for query. However, I want to include the content of a form, how can I insert data to two different tables based on the content?
Give me a thought. thank you !!
------ Solution --------------------
Associated array can be used to solve
------ Solution --------------------
Join tables, has_tables, BELONGS_TO, and many_to_tables can be used.
------ Solution --------------------
The second floor is correct. I typed the error and used the association model.
Take a look, TP manual, 6.23 associated model
6.23.4 associated operations
In addition to associated queries, the system also supports automatic writing, updating, and deletion of associated data.
Join write
$ User = D ("User ");
$ Data = array ();
$ Data ["account"] = "ThinkPHP ";
$ Data ["password"] = "123456 ";
$ Data ["Profile"] = array (
'Email '=> 'liu21st @ gmail.com ',
'Nickname' => 'year ',
);
$ Result = $ User-> relation (true)-> add ($ user );
In this way, the associated Profile data is automatically written.
Similarly, you can use parameters to control the data to be joined and written:
$ Result = $ User-> relation ("Profile")-> add ($ user );