我看过很多帖子,但没有一个真正起作用。有人可以提供一种干净/清晰的方法来将 Codeigniter 与 Mac 上的 MS SQL Server 连接起来吗?这是高层次的,但我还没有看到清楚地证明这一点的解决方案。非常感谢!
最佳答案
我已经这样做了,在你的 application/config/database.php
中放置以下内容:
// This address is valid if you're on the same domain as the server:
// If not, you can put the ip address or url here as well.
$db['default']['hostname'] = 'DBComputerName\SQLEXPRESS';
// if you need a non default port uncomment and edit
//$db['default']['port'] = '5432';
$db['default']['username'] = 'databaseUsername';
$db['default']['password'] = 'databasePassword';
$db['default']['database'] = 'DatabaseName';
$db['default']['dbdriver'] = 'sqlsrv';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = FALSE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
我知道这有多令人沮丧,请注意,并非所有 Active Record 函数都可以正常工作或按预期工作,这是由于许多 SQL 服务器的怪癖造成的。
我建议将大部分 Active Record 查询切换为:$this->db->query();
PS 如果我没记错的话,MSSQL 没有预先配置的用户名,您需要创建一个用户名并允许从子网外部访问数据库。
引用这个来创建数据库用户:
http://technet.microsoft.com/en-us/library/aa337545.aspx
并允许访问:
http://support.webecs.com/KB/a868/how-do-i-configure-sql-server-express-to-allow-remote.aspx
关于sql-server - 如何将 codeigniter 连接到 SQL 服务器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19460025/