Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the use of JSON field types in ORM

2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

JSON field type in the use of ORM is how, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.

The use of JSON Field Type in ORM

The ThinkPHP5.1 version has been officially released for some time, and I will introduce the new features one after another. What I'm going to tell you about today is a feature that many users may not know yet: JSON field data support.

First of all, however, note that the support for JSON field data described in this article was introduced from the V5.1.4 + version. For reasons that include security updates, it is recommended that you use version 5.1.9+.

The definition of the JSON field in this article includes the JSON type or the saved data is a character type in JSON format, so theoretically there is no requirement for the database type and version except for the JSON field condition query.

The Db class operates on JSON

If you do not use the model class, the Db class provides a json method to specify your data table JSON format fields. For example, if your user table has an info field of type JSON, you can manipulate the data in the following ways.

Data writing

$user ['name'] =' thinkphp'

$user ['info'] = [

'email'= >' thinkphp qq.com'

'nickname'= >' fleeting time'

]

Db::name ('user')

-> json (['info'])

-> insert ($user)

The parameter of the json method is an array, and the info field is specified in the example, but you can actually specify multiple JSON type fields.

Data query

Query the entire JSON data usage.

$user=Db::name ('user')

-> json (['info'])

-> find (1)

Dump ($user)

The returned query result data will automatically contain an array type of info data, that is, the JSON format data has been automatically json_decode processed.

The query in this way does not strictly require the use of JSON types for info fields.

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report