如何使用mssql连接配置Codeigniter 4?

问题描述 投票:0回答:3

我想使用 SQL Server 配置 CI4 连接。 如果在CI3

$db['dbsqlsrv'] = array(
 'dsn' => '',
 'hostname' => 'localhost',
 'port' => '1433',
 'username' => 'sa',
 'password' => 'example',
 'database' => 'example',
 'dbdriver' => 'sqlsrv',
 'dbprefix' => '',
 'pconnect' => FALSE,
 'db_debug' => (ENVIRONMENT !== 'production'),
 'cache_on' => FALSE,
 'cachedir' => '',
 'char_set' => 'utf8',
 'dbcollat' => 'utf8_general_ci',
 'swap_pre' => '',
 'encrypt' => FALSE,
 'compress' => FALSE,
 'stricton' => FALSE,
 'failover' => array(),
 'save_queries' => TRUE
);

如何配置此选项以在 CI4 中工作。因为当我将.env database.default.DBDriver = MySQLi更新为database.default.DBDriver = Mssql时无法工作。

sql-server codeigniter codeigniter-4
3个回答
0
投票

在 CI4 中,您可以使用

'DBDriver' => 'SQLSRV'
,如以下 CI4 文档 URL 中所述

https://codeigniter.com/user_guide/database/configuration.html

完整的区块如下

public $default = [
'DSN'      => '',
'hostname' => 'localhost',
'username' => 'YOUR_USER',
'password' => 'YOUR_PASSWORD',
'database' => 'DATABASE_NAME',
'DBDriver' => 'SQLSRV',
'DBPrefix' => '',
'pConnect' => false,
'DBDebug'  => (ENVIRONMENT !== 'production'),
'cacheOn'  => false,
'cacheDir' => '',
'charset'  => 'utf8',
'DBCollat' => 'utf8_general_ci',
'swapPre'  => '',
'encrypt'  => false,
'compress' => false,
'strictOn' => false,
'failover' => [],
'port'     => 1433

];

希望这有帮助:)


-1
投票

要在 codeigniter 4 中使用 mysql 数据库,您应该保留对于 mysql,您应该保留以下更改。 在 .env 文件中

database.default.DBDriver = MySQLi

在应用程序/Config/Database.php中

public $default = [
...
DBDriver=>'MySQLi',
...
];

-1
投票

代码点火器4

在应用程序>>配置>>Database.php

检查 $defaultGroup

public $defaultGroup = 'default';

public $default = [
    'DSN'      => '',
    'hostname' => 'localhost',
    'username' => 'YOUR_USER',
    'password' => 'YOUR_PASSWORD',
    'database' => 'DATABASE_NAME',
    'DBDriver' => 'MySQLi',
    'DBPrefix' => '',
    'pConnect' => false,
    'DBDebug'  => (ENVIRONMENT !== 'production'),
    'cacheOn'  => false,
    'cacheDir' => '',
    'charset'  => 'utf8',
    'DBCollat' => 'utf8_general_ci',
    'swapPre'  => '',
    'encrypt'  => false,
    'compress' => false,
    'strictOn' => false,
    'failover' => [],
    'port'     => 3308,
];
© www.soinside.com 2019 - 2024. All rights reserved.