Laravel表前缀配置
文章描述:
Laravel配置表前缀和使用
1、.env
DB_PREFIX=la_
2、config/database.php
use Illuminate\Support\Env;
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => env('DB_PREFIX'),
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],
控制器
echo env('DB_PREFIX');
$users = DB::select('SELECT * FROM `users` WHERE `id` = ?', [1]);
$users = DB::table('users')
->where('id', '>', 0)
->get();
发布时间:2023/03/27
发表评论