Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use save method in thinkphp5

Shulou Source: shulou.com Published: 2022-06-01 14:40:26 10月04日 Update

This article is a detailed introduction to "how to use the save method in thinkphp5". The content is detailed, the steps are clear, and the details are properly handled. I hope this article "how to use the save method in thinkphp5" can help you solve your doubts. Let's go deeper and learn new knowledge together with the ideas of the small editor.

In thinkphp5, the save() method is used to add a record to the specified data table. This method can only add one new record to the table at a time. Add multiple records repeatedly. The syntax is "Model object-> save(array)" or "Model object-> data(array) -> save();".

Operating environment: Windows 10 system, ThinkPHP5 version, Dell G3 computer.

How to use the save method in thinkphp5

Add a single data:save( ) method

Function: Add a record to the specified data table

This method can only add one new record to the table at a time, adding multiple records can be repeated, but saveAll() to learn later can add multiple records at once

The save method is one of the more complex methods in the Model class because it has multiple roles, not only for adding, but also for updating data.

Basic grammar:

Format 1: Write the data directly in the save method parameter

model object-> save(array);

Format 2: First generate data objects, and then use the save method to write directly to the table

model object-> data(array) -> save();

Both syntaxes can be added. But the second grammar structure is clearer, readable and easier to modify.

Tags: Data methods objects arrays datasheets models syntax plus one original multiple articles new records success content fields stars format only learning complex Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn MariaDB MySQL Shulou Technology Apple