更改Laravel中的基本PDO配置 [英] Alter base PDO configuration in Laravel

查看:510
本文介绍了更改Laravel中的基本PDO配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的共享Web主机在查询准备方面存在一些问题,我想启用PDO的模拟准备,config\database.php中对此没有任何选择.

My shared web host have some problems with query prepares and I want to enable PDO's emulated prepares, there's no option for this in the config\database.php.

在Laravel中有什么方法可以做到吗?

Is there any way I can do that in Laravel?

推荐答案

您可以在config/database.php中添加选项"数组以向数据库连接中添加选项:

You can add an "options" array to add options to your Database Connection within config/database.php:

    'mysql' => [
        'driver' => 'mysql',
        'host' => env('DB_HOST', 'localhost'),
        'port' => env('DB_PORT', '3306'),
        'database' => env('DB_DATABASE', 'forge'),
        'username' => env('DB_USERNAME', 'forge'),
        'password' => env('DB_PASSWORD', ''),
        'charset' => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix' => '',
        'strict' => false,
        'engine' => null,
        // Additional options here
        'options'   => [PDO::ATTR_EMULATE_PREPARES => true, PDO::MYSQL_ATTR_COMPRESS => true,]
    ],

您将看到我也为连接打开了MYSQL_ATTR_COMPRESS.

You will see I've also switched on MYSQL_ATTR_COMPRESS for my connection.

您可以在此处找到有关它们内置的某些选项的更多信息:

You can find more information on some of the options they have built in here:

https://github.com/laravel/framework/blob/master/src/Illuminate/Database/Connectors/Connector.php

这篇关于更改Laravel中的基本PDO配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆