文档https://www.workerman.net/doc/webman/db/migration.html 中的例子不太好.还要重新配一次数据库
这样数据库只要配置一次其他还有加载数据库的可以参考下面写法
/**
* Phinx 迁移配置
*/
require __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/support/bootstrap.php';
$defaultConnection = config('database.connections');
return [
'paths' => [
'migrations' => __DIR__ . '/database/migrations',
'seeds' => __DIR__ . '/database/seeds',
],
'environments' => [
'default_migration_table' => 'phinxlog',
'default_environment' => 'development',
'development' => [
'adapter' => 'pgsql',
'host' => getenv('DB_HOST') ?: '127.0.0.1',
'port' => getenv('DB_PORT') ?: '5432',
'name' => getenv('DB_NAME') ?: 'pi_memory_cloud',
'user' => getenv('DB_USER') ?: 'pi_memory',
'pass' => getenv('DB_PASSWORD') ?: '',
'charset' => 'utf8',
],
'production' => [
'adapter' => 'pgsql',
'host' => getenv('DB_HOST') ?: '127.0.0.1',
'port' => getenv('DB_PORT') ?: '5432',
'name' => getenv('DB_NAME') ?: 'pi_memory_cloud',
'user' => getenv('DB_USER') ?: 'pi_memory',
'pass' => getenv('DB_PASSWORD') ?: '',
'charset' => 'utf8',
],
],
];
require __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/support/bootstrap.php';
$dbConfig = config('database', []);
$defaultConnection = $dbConfig['default'];
$connectionConfig = $dbConfig['connections'][$defaultConnection];
return
[
"paths" => [
"migrations" => "database/migrations",
"seeds" => "database/seeds"
],
"environments" => [
"default_migration_table" => "phinxlog",
"default_environment" => "dev",
"dev" => [
"adapter" => $connectionConfig['driver'],
"host" => $connectionConfig['host'],
"name" => $connectionConfig['database'],
"user" => $connectionConfig['username'],
"pass" => $connectionConfig['password'],
"port" => $connectionConfig['port'],
"charset" => $connectionConfig['charset']
]
]
];
你的解析不了env函数,用这个
优秀!
厉害, 我目前自己使用直接使用env读取了
对,我也改了