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.

Advertisements

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 Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s