I have a column value stored in the database as:
a:2:{i:0;s:2:\"US\";i:1;s:2:\"19\";}
I want to unserialize it during the mysql
How about this? This is a MySQL user-defined function with embedded php:
CREATE FUNCTION unserialize_php RETURNS STRING SONAME 'unserialize_php.so';
Usage example:
SELECT unserialize_php('O:8:"stdClass":2:{s:1:"a";s:4:"aaaa";s:1:"b";s:4:"bbbb";}', "$obj->a")
AS 'unserialized';
+--------------+ | unserialized | +--------------+ | aaaa | +--------------+ 1 row in set (0.00 sec)
drop function unserialize_php;
Source: https://github.com/junamai2000/mysql_unserialize_php
You can create a MySQL user-defined function and call zend_eval_string
inside of the function so that you can bring back PHP variables to a MySQL result. I implemented a sample program. You can try it.