ThinkPHP database problems

Source: Internet
Author: User
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 );


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.