Jump to content

Accessing MSSQL with PHP


phpjoy

Recommended Posts

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.

 

Thank you.

Link to comment
https://forums.phpfreaks.com/topic/244310-accessing-mssql-with-php/
Share on other sites

echo $row;

 

This won't work.  $row is an array of values that represents the row of data retrieved from the database.  You would need to address it as an array to echo the contents(echo $row['fieldNameFromDatabase'], or use print_r($row) to pull the raw contents of the array onto the screen.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.