laravel中DB查询数据库后,返回的对象转为数组
先编码成json字符串,再解码成数组
/**
* [objectToArray 先编码成json字符串,再解码成数组]
* @param  [type] $object [description]
mysql 字符串转数组* @return [type]        [description]
*/
public function objectToArray($object) {
return json_decode(json_encode($object), true);
}
DB查询数据库
$res = DB::connection('mysql_crm')->table('yu_school_ersanshi')->get()->map(function ($value){
return (array)$value;
});
return gettype($res[0]);
//return $res[0]['id'];
原⽣sql查询出来的数据
$sql = "select a.zwmc,a.id,a.szgj from gwdxyxk as a left join yu_school_ersanshi as b on a.id=b.s_ys_id where a.szgj='a0920192AD18538XLtaQ' t1 is null and a.zwmc is not null"; $res = DB::connection('mysql_crm')->select($sql);
$a = array_map(function ($value){
return (array)$value;
},$res);
return $a[0];
//return gettype($a[0]);

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。