Reputation: 23
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
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 :
How to use PHP to connect to sql server
Connecting to an SQL Server Database with PHP
Upvotes: 1
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