这是我的database.php
文件:
'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'learning_laravel',
'username' => 'forge',
'password' => 'bomb',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
我的route.php
文件:
<?php
Route::get('/',function(){
$username=DB::table('username')->get();
return $username;
});
我创建了一个名为learning_laravel的数据库,并创建了一个名为username的表并为其提供了输入,但我没有得到任何输出。
当我通过输入 php artisanserve 打开 localhost:8000/时,这是我得到的输出。
我的输出文件:
Database[]not configured
$connections = $this->app['config']['database.connections'];
if (is_null($config = array_get($connections, $name)))
{
throw new \InvalidArgumentException("Database [$name] not configured.");
}
最佳答案
您尚未配置数据库连接。
您可以在以下文件 app/config/database.php
中找到配置示例内容
'default' => 'mysql', //your database name according to prefix in connections subarray
'connections' => array(
'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'your database name here',
'username' => 'your username here',
'password' => 'your password here',
'charset' => 'utf8',
'collation' => 'utf8_bin',
'prefix' => '',
),
关于php - 访问Laravel数据库时无输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24908787/