Save an array into database table

Description:

How to save an Array variable as a regular database value?

Solution:

PHP offers the serialize() function, that creates a representation of the variable that can be stored everywhere. This can be used for other types of variables as well, but it is most common for Array.

myqsl_query(“INSERT INTO table_name(column_name) VALUES(“.serialize($array_variable).”)”);

 

To return the value, we can use the unserialize() function, for the serialized object.

About admin

Just another php developer trying to give something back to the community.
This entry was posted in PhP, SQL and tagged , , . Bookmark the permalink.

Leave a comment