Ozi Oz
Ozi Oz

Reputation: 289

How to connect to SQL Server using PHP

I have this code which I use in order to connect to SQL Server.

$host="";
$uid="sa";
$passVal="";
odbc_connect("Driver={SQL Server};Server=$host;",$uid, $passVal);

How should I check the connection? I mean what should I put in my code? like:

If connection was set then output "connected" else "disconnected"

And, how can I select the database here? Should it be something like:

$database="";
odbc_connect("Driver={SQL Server};Server=$host;",$uid, $passVal, $database);

Upvotes: 0

Views: 281

Answers (1)

Rohit Choudhary
Rohit Choudhary

Reputation: 2259

odbc_connect("Driver={SQL Server Native Client 10.0};Server=$host;Database=$database;",$uid, $passVal, ) or  die("Connection could not established");

For you reference http://php.net/manual/en/function.odbc-connect.php

Upvotes: 3

Related Questions