0

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...

Stefen Wiranata
  • 127
  • 1
  • 5
  • 13

3 Answers3

2

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.

WEIZ
  • 47
  • 1
  • 8
  • i check sql server port is 1433 , and change false autoinit , but it's just prevent init db when first load , that not solve the problem , what do you mean with addressed some problem in server ? please help.. – Stefen Wiranata Oct 16 '13 at 09:40
  • I'm so sorry, that problem was solved by another department. So I don't know what that problem is. – WEIZ Oct 16 '13 at 10:01
2

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.

Stefen Wiranata
  • 127
  • 1
  • 5
  • 13
1

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.

Community
  • 1
  • 1
Petre Pătraşc
  • 2,203
  • 2
  • 19
  • 17
  • sorry for troubling you, and my bad english , i dont understand your solution in there , i spend my whole time because this problem, what you use ? sqlsrv or odbc ? " I found out that the problem was CodeIgniter's built-in ODBC driver, which adds apostrophes around the table names. I had a quick look through odbc_driver.php, changed the way tables are referenced", what you change ? please help.. – Stefen Wiranata Oct 16 '13 at 09:14
  • @StefenWiranata I went for ODBC in that example, since I couldn't get "sqlsrv" to work under PHP 5.3. – Petre Pătraşc Oct 16 '13 at 12:29
  • @StefenWiranata Hey man, just updated my answer to reflect part 2 of your comment. – Petre Pătraşc Oct 16 '13 at 13:19
  • 1
    thank you for your help , finally i figured it out, try to show sqlsrv error by add die(print_r(sqlsrv_errors(), true)); on DB_driver and read the error log – Stefen Wiranata Oct 17 '13 at 02:42