laravel 4.2从phpmyadmin创建mysql数据库而不使用迁移

时间:2022-09-27 16:43:18

i tried it and it says that data base was connected, we can do queries too.

我试过它,它说数据库是连接的,我们也可以做查询。

Route::get('database-test', function(){
    if(DB::connection()->getDatabaseName()){
        echo 'connected'.DB::connection()->getDatabaseName();

    }
});

Route::get('staff', function(){
    $results = DB::select('select * from users where staff_id = ?', array(1));
    echo '<pre>';
    print_r($results);
    print_r($results[0]) ;

    echo '</pre>';
});

these routes were ok. but when try to use codes like following,

这些路线还可以。但是当尝试使用如下代码时,

$users = DB::table('users')->get();

foreach ($users as $user)
{
    var_dump($user->name);
}

it gives errors.

它给出了错误。

please help me to solve my problem. thanks in advance

请帮我解决我的问题。提前致谢

1 个解决方案

#1


0  

Hey in your Routes use your code its working perfect

嘿,在你的路线中使用你的代码,它的工作完美

Route::get('staff', function(){
$users = DB::table('users')->get();

foreach ($users as $user)
{
    var_dump($user->name);
}

}); 

you will get output :) working for me :)

你会得到输出:)为我工作:)

#1


0  

Hey in your Routes use your code its working perfect

嘿,在你的路线中使用你的代码,它的工作完美

Route::get('staff', function(){
$users = DB::table('users')->get();

foreach ($users as $user)
{
    var_dump($user->name);
}

}); 

you will get output :) working for me :)

你会得到输出:)为我工作:)