简体   繁体   中英

Connecting to SQL Server 2012 from Linux VM via Codeigniter

I created a Virtual Machine with Ubuntu Desktop 12.0.4 LTS.

On it, I have installed Apache2, php5, MySQL.

I have read a ton of posts trying to understand how to connect to a SQL Server database on another box, but I haven't quite got it figured out.

On the Linux box, I installed unixODBC and FreeTDS and I can connect to the database and execute queries at a command-line level.

What I need is the ability to configure Codeigniter on the Linux box to talk to the SQL Server instance on the Windows box.

I assume that the unixODBC and FreeTDS installations can be leveraged, yet I'm not sure how to go about it.

Included is a copy of my database.php configuration file from Codeigniter:

$db['default']['hostname'] = '<ip address, port #>';
$db['default']['username'] = 'username';
$db['default']['password'] = 'password';
$db['default']['database'] = 'database name';
$db['default']['dbdriver'] = 'odbc';
$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;

In my php.ini file, I set the extension_dir to point to the directory where the freetds drivers are located and I defined the driver file "extension=libtdsodbc.so".

Anyone experienced in this area?

Thanks for your time.

yo only need the .so package please, read the next link https://docs.moodle.org/28/en/Installing_MSSQL_for_PHP for more information

and the config file

$db['default']['hostname'] = '<ip address, port #>';
$db['default']['username'] = 'username';
$db['default']['password'] = 'password';
$db['default']['database'] = 'database name';
$db['default']['dbdriver'] = 'mssql';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM