2

I want to ask you about how to connect to MSSQL Server 2005 using PHP?

I got error like this :

Connection could not be established. 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 ) )

and here is my PHP code :

<?php
    $serverName = "192.168.183.249\MSSQLSERVER, 1542"; //serverName\instanceName, portNumber default is 1433)
    $connectionInfo = array( "Database"=>"SEI_AproCS", "UID"=>"sa", "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));
    }
?>

Please help to advice.

THanks

1

4 Answers 4

2

You just need to install driver from this link PHP Driver

You can follow this link for tutorial PHP MSSQL Tutorial

An other option is to connect to mssql using DSN ,
and this easy way you just to enable mssql extension in php

And follow this link to create DSN Create DSN in windows

Also follow this link to connect using php and DSN Connect php using DSN

Sign up to request clarification or add additional context in comments.

4 Comments

I just followed that step and still can't connect :(
is mssql local at your machine ? and do you have to use this method ?
I using php_sqlsrv_54_ts.dll, not mssql. I have tried using mssql but for PHP 5.4 cant
@Kongkow see the new edits , and don't forget to install mssql server at your local machine if you use local mssql database .
1

To connect with sql server you need to add dll file for sql server in the directory

wamp\bin\php\php5.3.0\ext

Comments

1

Try PDO:

//$pdo = new PDO("sqlsrv:Server=$hostname;Database=$dbname;", $username, $password);  // works with proper driver for PHP.
$pdo = new PDO("odbc:Driver={SQL Server};Server=$hostname;Database=$dbname;", $username, $password);  // works with proper driver for ODBC and PHP ODBC.

I could not get the first line to work due to weird compiler version incompatibilities, but the second one worked fine after installing Microsoft ODBC Driver 11 for SQL Server

PHP Version 5.3.0 has built-in ODBC support, according to php.ini, but that still lists an active extension=php_pdo_odbc.dll here.

Comments

0

You instal driver. ODBC

  • msodbcsql_x64.msi #System Operation 63
  • msodbcsql_x86.msi #System Operation 86/32

link download https://www.microsoft.com/en-us/download/details.aspx?id=36434

good luck

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.