在您的 application/config/database.php 文件中:
$db['sqlserver']['username'] = 'db_username';
$db['sqlserver']['password'] = 'db_password';
$db['sqlserver']['database'] = 'db_database';
$db['sqlserver']['hostname'] = 'sqlsrv:server=db_servername;Database=' . $db['sqlserver']['database'];
$db['sqlserver']['dbdriver'] = 'pdo';
$db['sqlserver']['dbprefix'] = '';
$db['sqlserver']['pconnect'] = FALSE;
$db['sqlserver']['db_debug'] = TRUE;
$db['sqlserver']['cache_on'] = FALSE;
$db['sqlserver']['cachedir'] = '';
$db['sqlserver']['char_set'] = 'utf8';
$db['sqlserver']['dbcollat'] = 'utf8_general_ci';
$db['sqlserver']['swap_pre'] = '';
$db['sqlserver']['autoinit'] = TRUE;
$db['sqlserver']['stricton'] = FALSE;
前四个值显然需要设置为您拥有的任何配置(db_username
, db_password
, db_database
, db_servername
)。
并设置活动组:
$active_group = 'sqlserver';
使用 PDO 通常更安全(https://code.tutsplus.com/tutorials/why-you-should-be-using-phps-pdo-for-database-access--net-12059)。
如果还没有安装/启用 sqlsrv PDO 驱动程序,请不要忘记安装/启用它。
https://www.microsoft.com/en-us/download/details.aspx?id=20098 - 如果在 Windows 上