How to connect PHP to SQL Server?

I am trying to connect to SQL Server using PHP, I am learning this language.

I read that perhaps the ODBC connection is the best, I created my ODBC, but I don't know how to use it with PHP while I try this:

$server = 'MyServer\MyDB';

// Connect to MSSQL
$link = mssql_connect=($server, 'MyUser', '');

if (!$link) {
    die('You cannot connect to MSSQL');
}

When doing this, I get this message:

OBJECT NOT FOUND, ERROR 404.

But the ODBC test is fine.

SQL Server is located on the same PC, so maybe I don’t need to enter an IP address.

Is there anyone who can help?

+3
source share
1 answer

It seems you might have a typo. Here is an example from the documentation :

// Server in the this format: <computer>\<instance name> or 
// <server>,<port> when using a non default port number
$server = 'KALLESPC\SQLEXPRESS';

// Connect to MSSQL
$link = mssql_connect($server, 'sa', 'phpfi');

if (!$link) {
    die('Something went wrong while connecting to MSSQL');
}

You mistakenly placed =after mssql_connecttrying to complete the task (as far as the interpreter is concerned).

MSSql PHP, mssql. , .

+2

All Articles