Accessing MSSQL with PHP

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
phpjoy
Forum Newbie
Posts: 1
Joined: Tue Aug 09, 2011 5:16 am

Accessing MSSQL with PHP

Post by phpjoy »

Hi, I am trying to access the SQL Server 2005 with PHP. For that I have activated IIS 7 on the windows small business server, for PHP. Now I have the following code for local web hosting :

=====================================


<head>
<meta http-equiv="refresh" content="2";url="index.php";>
<title>Trial 1</title>

</head>
<h1>
:: B List ::
</h1>


<?php

$now = time();
echo $now;

$link = mssql_connect("SRVR name", "local host \ user name", "password");

if (!$link)
{
die('ERROR: Could not connect');
}


mssql_select_db('database name', $link);


$query = mssql_query('SELECT B_No, FROM dbo.B_LIST WHERE B_No = 000011', $link);

if (!$query)
{
die('MSSQL error');
}

$row = mssql_fetch_row ($query);


echo $row;


?>


<body>
</body>
</html>
=========================================

In this I am just trying to print one row from the database on the webpage
Correct me if I am wrong, as I am coding PHP for the first time with online help.

When I try to access the webpage on the explorer I only get the title and the page if refreshed every 2 seconds , and the time is displayed. Nothing is available from database.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Accessing MSSQL with PHP

Post by califdon »

http://www.php.net/manual/en/function.mssql-connect.php
Your connection command probably needs to look like this:

Code: Select all

$link = mssql_connect("localhost", "root", "abcxyz");
but you have to know what the username and password really are. "root" and "abcxyz" and "SRVR name" are just examples. Your MSSQL installation will surely have different names.
Post Reply