Skip to content
Advertisement

unserialize() expects parameter 1 to be string, array given

I am storing data in mysql table by serialize method, now I want to print all data So I wrote mysql query and trying to unserialize because data is in serialize format but unserialize showing error.

Error:

JavaScript

Query to fetch all records

JavaScript

Advertisement

Answer

Your $result variable contains a multi-dimensional array.

Assuming that some of the data in the table is serialized, and since you have not posted your table schema, here is a sample table that I hope matches your use case:

JavaScript

Running this code:

JavaScript

Will result in an array of objects, one for each line in your table, like this:

JavaScript

You need to run the following code in order to access the unserialized data:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement