Welcome Guest, Not a member yet? Register   Sign In
How to connect to sql server database
#1

[eluser]Mohammed Zayan[/eluser]
Hi there,
My PHP version is 5.4.7 and I have sql server 2005 installed in the computer.
I want to connect to sql server database.
I edit config\database.php
Code:
$db['default']['dbdriver'] = 'sqlsrv';
I download SQLSRV30.EXE from this link and setup it. It gives me some dll libraries
[Image: Rb7l1.jpg]
I take these dll and put it in
Code:
D:\xampp\php\ext
and I edit php.ini file and add
Code:
extension=php_sqlsrv_54_nts.dll
and restart xampp by stop it and start again.

I have this error
Fatal error: Call to undefined function sqlsrv_connect() in D:\xampp\htdocs\test\system\database\drivers\sqlsrv\sqlsrv_driver.php on line 76
How can I fix it??
#2

[eluser]Mohammed Zayan[/eluser]
I change the php.ini file
Code:
extension=php_sqlsrv_54_ts.dll
and restart xampp
and try to connect by this code
Code:
$serverName = '192.123.0.1';
$connectionInfo = array( "Database"=>"Middle", "UID"=>"sasa", "PWD"=>"******");
$conn = sqlsrv_connect( $serverName, $connectionInfo);

if( $conn ) {
     echo "Connection established.<br />";
}else{
     echo "Connection could not be established.<br />";
     die( print_r( sqlsrv_errors(), true));
}
I have this
Code:
Connection could not be established.<br />Array
(
    [0] => Array
        (
            [0] => IMSSP
            [SQLSTATE] => IMSSP
            [1] => -49
            [code] => -49
            [2] => This extension requires the Microsoft SQL Server 2012 Native Client. Access the following URL to download the Microsoft SQL Server 2012 Native Client ODBC driver for x86: http://go.microsoft.com/fwlink/?LinkId=163712
            [message] => This extension requires the Microsoft SQL Server 2012 Native Client. Access the following URL to download the Microsoft SQL Server 2012 Native Client ODBC driver for x86: http://go.microsoft.com/fwlink/?LinkId=163712
        )

    [1] => Array
        (
            [0] => IM002
            [SQLSTATE] => IM002
            [1] => 0
            [code] => 0
            [2] => [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
            [message] => [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
        )

)
#3

[eluser]Otemu[/eluser]
Check out this topic http://ellislab.com/forums/viewthread/171148/
#4

[eluser]Mohammed Zayan[/eluser]
I connect successfully and returned data by this code
Code:
&lt;meta http-equiv="content-type" c charset=utf-8" /&gt;
&lt;?php
$serverName = 'MyHost';
$connectionInfo = array( "Database"=>"MyDB", "UID"=>"DBUser", "PWD"=>"DBPass", "CharacterSet" =>"UTF-8");
$conn = sqlsrv_connect( $serverName, $connectionInfo);

if( $conn ) {
     $str_query = "SELECT * FROM Employee";
  $result = sqlsrv_query($conn, $str_query);
  if($result === FALSE){
  die( print_r( sqlsrv_errors(), true));
  }
  while( $obj = sqlsrv_fetch_object( $result)) {
  echo $obj->EmpName."<br />";
}
}else{
     echo "Connection could not be established.<br />";
     die( print_r( sqlsrv_errors(), true));
}

?&gt;
But I try to connect by codeigniter
config\database.php
Code:
$active_group = 'default';
$active_record = TRUE;

$db['default']['hostname'] = 'Host';
$db['default']['username'] = 'user';
$db['default']['password'] = 'pass';
$db['default']['database'] = 'DB';
$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;
and I have this problem

A Database Error Occurred

Unable to connect to your database server using the provided settings.

Filename: D:\xampp\htdocs\test\system\database\DB_driver.php

Line Number: 124
#5

[eluser]Mohammed Zayan[/eluser]
How can I fix this problem??
#6

[eluser]Damir Sivic[/eluser]
tray with new DB_driver.php from github

https://github.com/EllisLab/CodeIgniter/...driver.php


also:

http://ellislab.com/forums/viewthread/197527/
#7

[eluser]Mohammed Zayan[/eluser]
Thanks Damir Sivic
now it work.

I edit sqlsrv_driver.php file
Code:
function db_pconnect()
    {
        //$this->db_connect(TRUE);  // org
        return $this->db_connect(TRUE);
    }
#8

[eluser]stefenw[/eluser]
i follow all instructions in there ,
i download sqlsrv30.exe and add this to php.ini

extension=php_sqlsrv_54_ts.dll
extension=php_pdo_sqlsrv_54_ts.dll

i install Native Client 10
i change sqlsrv_driver.php in folder database-driver-sqlsrv

to

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

but it not work , still

Unable to connect to your database server using the provided settings.

Filename: C:\xampp\htdocs\HRM\system\database\DB_driver.php

Line Number: 124

what should i do ? please help




Theme © iAndrew 2016 - Forum software by © MyBB