Question

i want to connect to sql server my php version is 5.4 and i have MS SQL Server 2008 R2 and i use PHP Codeigniger 2.1.4 i use sqlsrv30.exe i use XAMPP 1.8.2

i change database.php config

$db['default']['hostname'] = '192.168.5.208';
$db['default']['username'] = 'xxx';
$db['default']['password'] = 'xxx';
$db['default']['database'] = 'xxx';
$db['default']['dbdriver'] = 'sqlsrv';
$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 download sqlsrv30.exe. install it in php/ext

i add the following on the php.ini file:

extension=php_sqlsrv_54_ts.dll

i install Native Client 10

i change sqlsrv_driver.php in folder database-driver-sqlsrv to

function db_pconnect() {
        //return $this->db_connect(TRUE);
        return $this->db_connect(TRUE);
    }

i also try add

db['default']['port'] = 1433;

but its still not working. I always encountered the ff. error:

A Database Error Occurred
Unable to connect to your database server using the provided settings.
Filename: C:\xampp\htdocs\HRM\system\database\DB_driver.php
Line Number: 124

Please help...

Was it helpful?

Solution 3

I've had the same trouble you've had about a year ago. Have a look at the replies here, there are some great suggestions from people in there: CodeIgniter MSSQL connection

@StefenWiranata Sorry, just noticed part 2 of your comment - I can't remember where I'd made the change, but I can try and look tonight if you can't get it solved. I know for sure that CI was adding apostrophes around the table names somewhere in system/database/drivers/odbc/, most likely in the odbc_driver.php file.

OTHER TIPS

My mysql had the same problem in the same line and I search a lot for it. It may be your 'port' or 'autoinit'. But mine finally resovled by addressed some problem in server. So check your server is another way.

Finally figure it out , add die(print_r(sqlsrv_errors(), true)); on DB_driver and read the error log and solve your problem , for me because I just install Native Client 10 and the sqlsrv3.0 require Native Client 11.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top