php - 访问Laravel数据库时无输出

标签 php mysql laravel

这是我的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/

相关文章:

php - array_map 导致服务器崩溃

php - 记住我 cookie 伪造

mysql - 从 Magento 1.9 数据库获取客户姓名、电子邮件和电话号码

php - 第二个查询仅显示初始查询的某些行的数据

php - 在数据库中插入下拉菜单项

Laravel:使用 Bref 在 AWS Lambda 上出现 Imagick 和 GD 错误

php - 解释 Eloquent morph 很多参数

php - Zend Studio 和 PHPUnit 入门问题

php - jQuery 和 PHP : Encode & Decode URL

php - Laravel 4.2 - Composer 更新问题