3

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

I have read that probably a ODBC connection is the best, I have created mine ODBC but I don't know how to use it from PHP, so far I'm trying this:

$server = 'MyServer\MyDB';

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

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

When running this I get this message:

OBJECT NOT FOUND, ERROR 404.

But ODBC test is fine.

The SQL Server is located in the same PC, so maybe I don't need to input the IP.

Is there anybody who can help?

0

1 Answer 1

3

It appears you may have a typo. Here's 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 an = after mssql_connect, attempting to make an assignment (as far as the interpreter is concerned).

As for using MSSql with PHP, have a look at the relevant mssql functions. Next you would select your database, and then begin querying it.

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

1 Comment

Shouldn't it be "as far as the interpreter is concerned" rather than compiler?

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.