user2866142
user2866142

Reputation: 23

Connecting php to MS SQL server 2008

I need a connection script of php and MS SQL: in trying the following but it doesn't work

$server = 'MVEKELDG156\SQLEXPRESS'; $username   = 'EDUC.PWV.GOV.ZA\Mveke.L';    
$password   = 'password@'; $database    = 'SAMS_EMIS_Warehouses';       
if(!mysql_connect($server, $username, $password)) { exit('Error: could not 
establish database connection'); } if(!mysql_select_db($database)) { 
exit('Error: could not select the database'); }

Upvotes: 2

Views: 213

Answers (2)

Tharif
Tharif

Reputation: 13971

The MSSQL extension is enabled by adding extension=php_mssql.dll to php.ini.

To get these functions to work, you have to compile PHP with --with-mssql[=DIR] , where DIR is the FreeTDS install prefix. And FreeTDS should be compiled using --enable-msdblib .

More References :

Installation

How to use PHP to connect to sql server

Connecting to an SQL Server Database with PHP

Upvotes: 1

Abdulla Nilam
Abdulla Nilam

Reputation: 38584

Check this

$myServer = "localhost";
$myUser = "your_name";
$myPass = "your_password";
$myDB = "SAMS_EMIS_Warehouses";

//connection to the database
$dbhandle = mssql_connect($myServer, $myUser, $myPass)
or die("Couldn't connect to SQL Server on $myServer");

//select a database to work with
$selected = mssql_select_db($myDB, $dbhandle)
or die("Couldn't open database $myDB

Source How to connect to MS SQL Server database

Upvotes: 0

Related Questions