【问题标题】:Error: Unsupported DB driver for windows and wamp错误:Windows 和 wamp 不支持的 DB 驱动程序
【发布时间】:2019-12-10 13:11:45
【问题描述】:

在我使用“mysql”作为驱动程序之前,我已经使用相同的信息配置了我的 .env 文件和 db.php 文件,但我尝试将其设为空并抛出相同的错误。

db.php

<?php
/**
 * Database Configuration
 *
 * All of your system's database connection settings go in here. You can see a
 * list of the available settings in vendor/craftcms/cms/src/config/DbConfig.php.
 *
 * @see craft\config\DbConfig
 */

return [
    'driver' => getenv(''),
    'server' => getenv('localhost'),
    'user' => getenv('root'),
    'password' => getenv('****'),
    'database' => getenv('craftyblog'),
    'schema' => getenv(''),
    'tablePrefix' => getenv(''),
    'port' => getenv('')
];

.env

# The environment Craft is currently running in ('dev', 'staging', 'production', etc.)
ENVIRONMENT="dev"

# The secure key Craft will use for hashing and encrypting data
SECURITY_KEY="******"

# The database driver that will be used ('mysql' or 'pgsql')
DB_DRIVER=""

# The database server name or IP address (usually this is 'localhost' or '127.0.0.1')
DB_SERVER="localhost"

# The database username to connect with
DB_USER="root"

# The database password to connect with
DB_PASSWORD="****"

# The name of the database to select
DB_DATABASE="craftyblog"

# The database schema that will be used (PostgreSQL only)
DB_SCHEMA=""

# The prefix that should be added to generated table names (only necessary if multiple things are sharing the same database)
DB_TABLE_PREFIX=""

# The port to connect to the database with. Will default to 5432 for PostgreSQL and 3306 for MySQL.
DB_PORT=""

DEFAULT_SITE_URL=""

我在这个版本中使用 WAMP:

PHP 7.1.16 阿帕奇 2.4.33 MySQL 5.7.21

希望能解决问题,谢谢。

【问题讨论】:

    标签: windows wamp craftcms


    【解决方案1】:

    在您的 config.php 中,您似乎正试图通过 getenv() 提取环境变量,但您将要用作字符串的实际值传递给 getenv() 函数而不是环境变量名。这些值在 .env 文件中设置,因此对于协作开发人员来说更便携。

    在那个 .env 文件中,没有为数据库驱动程序设置环境变量,因此您可以只在 config.php 中将字符串传递给“驱动程序”。

    如果您想从 .env 文件中提取值,请将变量名称作为环境变量的字符串以 getenv() 的预期格式传递,如下所示:

    config.php

    return [
        'driver' => 'mysql',
        'server' => getenv('DB_SERVER'),
        'user' => getenv('DB_USER'),
        'password' => getenv('DB_PASSWORD'),
        'database' => getenv('DB_DATABASE'),
        'schema' => getenv('DB_SCHEMA'),
        'tablePrefix' => getenv('DB_TABLE_PREFIX'),
        'port' => getenv('DB_PORT')
    ];
    

    您的 .env 文件似乎已经为所有内容设置好了,所以您应该一切顺利。但是,要在 config.php 文件中使用 .env 文件中的值,您需要将变量名称作为字符串传递。希望这会有所帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-06-30
      • 2018-08-12
      • 2021-08-28
      • 1970-01-01
      • 2021-08-22
      • 2021-09-21
      • 1970-01-01
      相关资源
      最近更新 更多