PHP and SQLServer connection

Question:

I'm trying to make a connection to SQLServer and PHP But the page gives me the following error:

Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: 192.168.2.7\SRVDOC\DOCSYSTEMSCAN in C:\wamp\www\conexao.php on line 2

Warning: mssql_select_db() expects parameter 2 to be resource, boolean given in C:\wamp\www\conexao.php on line 3

The current code is:

<?php
    $con = mssql_connect("192.168.2.7\SRVDOC\DOCSYSTEMSCAN", "sa", "minhasenha");
    mssql_select_db("fd_585b0f87", $con);
 ?>

I'm racking my brain but I don't know what it could be… Any suggestions? Thanks.

Answer:

Friend, try to follow the model proposed on the official PHP manual page:

$serverName = "SRVDOC\DOCSYSTEMSCAN"; //serverName\instanceName
$connectionInfo = array( "Database"=>"fd_585b0f87", "UID"=>"sa", "PWD"=>"minhasenha");
$conn = sqlsrv_connect( $serverName, $connectionInfo);

Reference: http://php.net/manual/en/function.sqlsrv-connect.php

Or try that way with the "mssql_connect" function

$server = 'SRVDOC\DOCSYSTEMSCAN';
$link = mssql_connect($server, 'sa', 'minhasenha');

Reference: http://bg2.php.net/manual/en/function.mssql-connect.php

Good luck!

Scroll to Top