[英]return data from mysql and unserialize it
My SQL 我的SQL
$query = "SELECT value FROM oc_setting WHERE setting_id =7258";
$result = $this->db->query($query);
return $result->rows;
when I var_dump
it show 当我
var_dump
它显示
array(1) {
[0]=>
array(1) {
["value"]=>
string(158) "a:1:{i:0;a:5:{s:8:"rss_link";s:11:"ddddddddddd";s:9:"layout_id";s:1:"2";s:8:"position";s:14:"content_bottom";s:6:"status";s:1:"1";s:10:"sort_order";s:1:"5";}}"
}
}
how can I unserialize array like this? 我该如何反序列化数组? cast to string first?
首先转换为字符串? I tried unserializ(var) but it say error coz it's an array.
我尝试过unserializ(var),但它说错误,因为它是一个数组。
PHP function unserialize
( http://php.net/manual/en/function.unserialize.php ) will help you. PHP函数反
unserialize
( http://php.net/manual/zh/function.unserialize.php )将为您提供帮助。
unserialize($result[0]['value']);
will return you the array. 将返回数组。
It seems you're using some PHP Framework (very similar to CodeIgniter one, but not sure). 看来您正在使用某些PHP框架(与CodeIgniter十分相似,但不确定)。 There should be a function to retrieve exactly one (first) row from the result set.
应该有一个函数可以从结果集中准确地检索到第一行。
Right now you're asking about a workaround which is not good. 现在,您正在问一个不好的解决方法。 Usually DB drivers have a good interface to get how many rows/columns it took from query/view.
通常,数据库驱动程序具有良好的接口,可以从查询/视图中获取多少行/列。
I usually use the following statement if I need go through the result array: 如果需要遍历结果数组,通常使用以下语句:
if ($result -> num_rows())
{
foreach ($result -> result_array() as $entry)
{
// do something
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.