Laravel 查询生成器 - 从 MySQL 获取当前时间
Laravel Query Builder - Get Current Time From MySQL
我想获取 MySQL 在 Laravel 5.1
的当前时间
我所做的是
$time = DB::select( DB::raw('SELECT NOW() AS end_time'));
return $time[0]['end_time'];
我收到这个-
我想要这样的输出-
2015-10-06 17:02:32
有人可以帮忙吗?
The select method will always return an array of results. Each result
within the array will be a PHP StdClass object, allowing you to access
the values of the results.
您收到的错误是因为您试图访问作为数组的第一个(也是唯一一个)结果,而它是一个 StdClass 对象。所以,试试看:
$results = DB::select(DB::raw('SELECT NOW() AS end_time'));
return $results[0]->end_time;
我想获取 MySQL 在 Laravel 5.1
的当前时间我所做的是
$time = DB::select( DB::raw('SELECT NOW() AS end_time'));
return $time[0]['end_time'];
我收到这个-
我想要这样的输出-
2015-10-06 17:02:32
有人可以帮忙吗?
The select method will always return an array of results. Each result within the array will be a PHP StdClass object, allowing you to access the values of the results.
您收到的错误是因为您试图访问作为数组的第一个(也是唯一一个)结果,而它是一个 StdClass 对象。所以,试试看:
$results = DB::select(DB::raw('SELECT NOW() AS end_time'));
return $results[0]->end_time;