Route::get('/hi', function(){
header('content-type:text/htmlcharset=utf8')
//$rs=DB::select('select * from cf_user limit 0,100')
$rs=User::find()
dd($rs)
//return"hi"
})
数据库:
数据库配置:
'mysql' =>[
'driver' =>'mysql',
'host' =>'localhost',
//'host' =>env('DB_HOST', 'localhost'),
'database' =>'test',
//'database' =>env('DB_DATABASE', 'forge'),
'username' =>'root',
//'username' =>env('DB_USERNAME', 'forge'),
'password' =>'qaz123',
//'password' =>env('DB_PASSWORD', ''),
'charset' =>'utf8',
'collation' =>'utf8_unicode_ci',
'prefix' =>'',
'strict' =>false,
],
如果是Laravel5,需要先在控制器里引用要使用的模型。比如:use App\User
取出所有记录:
$users = User::all()
根据主键取出一条数据:
$user = User::find(1)
var_dump($user->name)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)