CodeIgniter MSSQL Connection

I am working on a web project that will be deployed on a 64-bit machine running Windows 2008 Server with IIS 7.5 and PHP 5.3.8. The database in the system is Microsoft SQL Server 2008 R2. I am developing an application on the CodeIgniter 2.1.0 platform, and I am a little fixated on connecting to SQL Server.

I tried using the MSSQL, ODBC, and SQLSRV database drivers and ran into three separate errors for each other driver.

Here is my configuration for ODBC:

$db['default']['hostname'] = 'SA'; $db['default']['username'] = 'petre'; $db['default']['password'] = 'start'; $db['default']['database'] = 'petre'; $db['default']['dbdriver'] = 'odbc'; $db['default']['dbprefix'] = ''; $db['default']['pconnect'] = TRUE; $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; 

I have the DNS for SA defined in Data Sources, and I am sure that the username and password are valid and that the server accepts mixed authentication (Windows + SQL authentication).

I automatically load the database library and for any page that I get:

 Unable to connect to your database server using the provided settings. Filename: C:\inetpub\wwwroot\system\database\DB_driver.php Line Number: 124 

If I try to connect via MSSQL, I just get a blank page, no matter what.

If I try to use SQLSRV using the following parameters:

 $db['default']['hostname'] = '127.0.0.1'; $db['default']['username'] = 'petre'; $db['default']['password'] = 'start'; $db['default']['database'] = 'petre'; $db['default']['dbdriver'] = 'sqlsrv'; 

Even if I contact the sqlsrv dll file in php.ini, I get the following message:

 PHP Fatal error: Call to undefined function sqlsrv_connect() in C:\inetpub\wwwroot\system\database\drivers\sqlsrv\sqlsrv_driver.php on line 76 

I read old posts and different opinions, but I have not solved the problem yet.

I am looking for a solution for only one DB driver - everything that gets it to connect is fine. Does anyone have any tips for resolving it?

+4
source share
2 answers

The error displayed for the SQLSRV driver implies that the DLL never loads. What does your php_info () say?

In addition, do you have the Native Access Client (SNAC) 10 installed? To do this, you need the SQLSRV driver.

+2
source

For x86 win download http://www.microsoft.com/en-us/download/details.aspx?id=20098 for use with:

 <br/>$db['default']['dbdriver'] = 'sqlsrv'; <br/>use the php_sqlsrv_XX_ts_vcX.dll in php.ini extension 

If your web server and database server are not on the same server as your application, install this:

 http://go.microsoft.com/fwlink/?LinkID=188400&clcid=0x409 

and for linux as a web server:
$ db ['default'] ['dbdriver'] = 'mssql';

 download & install = php5-sybase + freetds <br/>edit /usr/local/etc/freetds.conf <br/>create pdo_dblib.so & php_mssql.so (if not allready exist on your extension dir), and apply to php.ini sudo /etc/init.d/apache2 restart 

and just do not forget to allow connection to your database (the default port for mssql is 1433)

+3
source

Source: https://habr.com/ru/post/1388470/


All Articles