1

大家好,我在这里只需要一些关于反序列化 MySQL 值的帮助。我想要的是从我的数据库中获取序列化值后,我将在变量中分配未序列化的值。

这是我的代码

//THIS IS THE QUERY

$sqlGetSerializedValues = "SELECT cscart_order_data.order_id AS order_id, cscart_order_data.data as data_serialize FROM cscart_orders
                           LEFT JOIN cscart_order_data
                           ON cscart_orders.order_id = cscart_order_data.order_id
                           WHERE type = 'I'";

$resultGetSerialize = $this->db->query($sqlGetSerializedValues);

$var_data = array();

foreach($resultGetSerialize->result_array() as $row1){
   $var_data[] = $row1['data_serialize'];
}
unserialize($var_data); //How can i get the selected value
print_r($var_data);

OUTPUT:

Array
(
    [0] => a:2:{s:6:"points";i:100;s:4:"cost";i:100;}
    [1] => a:2:{s:6:"points";i:100;s:4:"cost";i:100;}
    [2] => a:2:{s:6:"points";i:294;s:4:"cost";i:294;}
    [3] => a:2:{s:6:"points";d:107;s:4:"cost";d:107;}
    [4] => a:2:{s:6:"points";i:163;s:4:"cost";i:163;}
    [5] => a:2:{s:6:"points";i:322;s:4:"cost";i:322;}
    [6] => a:2:{s:6:"points";i:289;s:4:"cost";i:289;}
    [7] => a:2:{s:6:"points";i:9;s:4:"cost";i:9;}
    [8] => a:2:{s:6:"points";i:500;s:4:"cost";i:500;}
    [9] => a:2:{s:6:"points";i:500;s:4:"cost";i:500;}
    [10] => a:2:{s:6:"points";i:301;s:4:"cost";i:301;}
    [11] => a:2:{s:6:"points";i:500;s:4:"cost";i:500;}
    [12] => a:2:{s:6:"points";i:490;s:4:"cost";i:490;}
    [13] => a:2:{s:6:"points";i:103;s:4:"cost";i:103;}

例如,我想获取“点”并在变量 $points 中分配。我怎样才能做到这一点?也是成本。好的,在此先感谢。

4

2 回答 2

2

在您的循环中,您想在unserialize其中调用该函数:

foreach($resultGetSerialize->result_array() as $row1){
   $var_data[] = unserialize($row1['data_serialize']);
}

然后你会得到一个多维数组。现在你正在结束一个序列化值的数组。

于 2013-08-28T02:27:52.303 回答
1

据我所知,提取这些值(它们是PHP 的serialize() d,而不是 MYSQL)的唯一方法是使用 PHP 的unserialize()函数(此处的文档)

于 2013-08-28T02:26:26.140 回答