Home >Backend Development >PHP Tutorial >How to store PHP array into database
This article mainly introduces how to store PHP arrays into the database. It has certain reference value. Now I share it with you. Friends in need can refer to it
It turns out that array array cannot be directly inserted into the database. You have to use the json_encode() method, and the database columns must be set to text
Type | Size | Use |
TINYTEXT | 0-255 bytes | Short text string |
TEXT | 0-65 535 bytes | Long text data |
MEDIUMTEXT | 0-16 777 215 bytes | Medium length text data |
LONGTEXT | 0-4 294 967 295 bytes | Very large text data |
There are 4 TEXT types: TINYTEXT, TEXT, MEDIUMTEXT and LONGTEXT. The corresponding four BLOB types have different maximum storage lengths, which can be selected according to the actual situation.
json_encode(value)
value: array variable
json_decode(value)
value:Variable
Description | |
Encode variables in JSON | |
Decode strings in JSON format and convert them into PHP variables |
Summary of the cheat sheet in PHP strings
How PHP dynamically modifies the configuration file
How to use PHP to make the SWOOLE extension implement scheduled synchronization of MySQL data
The above is the detailed content of How to store PHP array into database. For more information, please follow other related articles on the PHP Chinese website!