配置文件添加配置 config/autoload/databases.php
return [
'default' => [],
'db2' => [
'driver' => env('DB_DRIVER_NET', 'mysql'),
'host' => env('DB_HOST_NET', 'localhost'),
'database' => env('DB_DATABASE_NET', 'hyperf'),
'username' => env('DB_USERNAME_NET', 'root'),
'password' => env('DB_PASSWORD_NET', ''),
'charset' => env('DB_CHARSET_NET', 'utf8'),
'collation' => env('DB_COLLATION_NET', 'utf8_unicode_ci'),
'prefix' => env('DB_PREFIX_NET', ''),
'pool' => [
'min_connections' => 1,
'max_connections' => 10,
'connect_timeout' => 10.0,
'wait_timeout' => 3.0,
'heartbeat' => -1,
'max_idle_time' => (float) env('DB_MAX_IDLE_TIME', 60),
],
'cache' => [
'handler' => Hyperf\ModelCache\Handler\RedisHandler::class,
'cache_key' => '{mc:%s:m:%s}:%s:%s',
'prefix' => 'default',
'ttl' => 3600 * 24,
'empty_model_ttl' => 600,
'load_script' => true,
],
'commands' => [
'gen:model' => [
'path' => 'app/Model/db2',
'force_casts' => true,
'inheritance' => 'Model',
],
],
],
];
使用命令生成模型
php bin/hyperf.php gen:model 表 --pool db2
生成的模型将保存到 app/Model/db2/
其他配置详见:hyperf-创建模型