我看过很多帖子,但没有一个真正有效。有人可以提供一种干净/清晰的方式将 Codeigniter 与 Mac 上的 MS SQL Server 连接起来吗?这是高级别的,但我还没有看到一个清楚地证明这一点的解决方案。非常感谢!
问问题
6143 次
2 回答
0
我已经这样做了,在您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 没有预先配置用户名,您需要创建一个用户名并允许从子网外部访问数据库。
请参阅此以创建 db 用户:
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
于 2013-10-18T22:38:17.010 回答
0
我使用 PDO 驱动程序...这对我有用:
$db['mssql']['hostname'] = 'sqlsrv:server=myserverIP;database=mydb;encrypt=true;trustservercertificate=true';
$db['mssql']['username'] = 'myun';
$db['mssql']['password'] = 'mypw';
$db['mssql']['database'] = 'mydb';
$db['mssql']['dbdriver'] = 'pdo';
$db['mssql']['dbprefix'] = '';
$db['mssql']['pconnect'] = TRUE;
$db['mssql']['db_debug'] = TRUE;
$db['mssql']['cache_on'] = FALSE;
$db['mssql']['cachedir'] = '';
$db['mssql']['char_set'] = 'utf8';
$db['mssql']['dbcollat'] = 'utf8_general_ci';
$db['mssql']['swap_pre'] = '';
$db['mssql']['autoinit'] = TRUE;
$db['mssql']['stricton'] = FALSE;
于 2013-10-21T12:34:41.083 回答