首页 > 解决方案 > 无法使用 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

);

标签: phpcodeigniter

解决方案


您可能在配置中有一些错误。确保您已正确配置数据库。在 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
);

推荐阅读