2

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'); }
Tharif
  • 13,794
  • 9
  • 55
  • 77
  • I'm not surprised it didn't work, you forgot to enter the code! – zanderwar Aug 06 '15 at 05:58
  • $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'); } – user2866142 Aug 06 '15 at 05:59

2 Answers2

1

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

Community
  • 1
  • 1
Tharif
  • 13,794
  • 9
  • 55
  • 77
0

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

Abdulla Nilam
  • 36,589
  • 17
  • 64
  • 85