php - 无法使用 Codeigniter 连接 SQL 服务器
问题描述
我开发了带有 SQL 服务器连接的 Codeigniter 应用程序。在 Windows 7 PC 上使用 PHP 5.6 时它已正确连接,但相同的应用程序无法在具有相同 PHP 版本的 Windows 10 上运行。显示错误
$db['default'] = array(
'dsn' => '',
'hostname' => '192.168.0.241',
'username' => 'sa',
'password' => 'mypw',
'database' => 'dbsrver',
'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
);
解决方案
您可能在配置中有一些错误。确保您已正确配置数据库。在 application/config/databse.php
$db['default'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'root',
'password' => 'write password if any otherwise leave it empty',
'database' => 'Your_Database_Name',
'dbdriver' => 'mysqli',
'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
);
推荐阅读
- google-sheets - Google 表格 IF 功能
- sql - Iterated sub sampling against distinct values, union results
- crystal-reports - 水晶报表:运行总计:计算公式
- regex - htaccess rewrite redirect with parameters in subfolder
- c# - OAEP 填充与 CreateSignature
- apache-camel - 设置端点(骆驼)
- c# - C# Regex 在特定字符之后获取值,但需要检查前一个字符
- docker - 纱线工作区和泊坞窗
- java - 让 Mockito 1.x 在前 N 次调用中抛出异常,然后返回一个值?
- powershell - Powershell - 如何使用 $List.convertAll() 或替代 C# 方法来克隆列表