【发布时间】:2018-02-18 00:53:39
【问题描述】:
我从表“拍卖”中获取数据
$players = DB::table('auction')->where('id',$id)->get();
我正在以这种形式获取数据
[
{
"id": 3,
"name": "Yogesh Singh",
"year": "BE",
"branch": "CE",
"division": "D",
"achievements": "College Cricket Team",
"base_price": 5000000,
"status": 1,
"manager": 0
}
]
现在我需要将这些数据转移到另一个表“团队”中,因此我做到了
DB::table('team')->insert(['player_id' => $id, 'player_type' => $player->player_type, 'name' => $player->name, 'price' => $player->price]);
它会抛出一个错误,指出此集合实例上不存在属性 [player_type]。
我很确定我无法将从数据库中获取的数据转换为数组。
我该怎么做?
【问题讨论】:
-
在查询生成器之前使用
DB::setFetchMode(PDO::FETCH_ASSOC); -
这是现在的错误,Class 'App\Http\Controllers\PDO'没找到
-
您的拍卖表中有 player_type 列吗?您正在尝试获取未知属性
-
在控制器@YogeshKumarSingh 中添加
use PDO命名空间