Page 1 of 1

MSSQL Data retrieve

Posted: Mon Jul 14, 2008 12:25 am
by kuttan939
Hi,

I am new to PHP. I have to get data from MSSQL database and create an XML file. I am attaching the code.

Code: Select all

<?php
$myServer = "192.168.0.26";
$myUser = "sa";
$myPass = "";
$myDB = "tavi";
 
//create an instance of the  ADO connection object
$conn = new COM ("ADODB.Connection")
  or die("Cannot start ADO");
 
//define connection string, specify database driver
$connStr = "PROVIDER=SQLOLEDB;SERVER=".$myServer.";UID=".$myUser.";PWD=".$myPass.";DATABASE=".$myDB;
  $conn->open($connStr); //Open the connection to the database
 
//declare the SQL statement that will query the database
$query = "SELECT TimeStamp,X,Y FROM tavi.Message";
 
//execute the SQL statement and return records
$rs = $conn->execute($query);
 
$num_columns = $rs->Fields->Count();
//echo $num_columns . "<br>";
 
for ($i=0; $i < $num_columns; $i++) {
    $rows[$i] = $rs->Fields($i);
}
echo "<table>";
 
while (!$rs->EOF) {
 
      echo "<tr>";
        echo "<?xml version='1.0' encoding='UTF-8'?><markers><marker lat='". $rows[$i]['lat']."' lng='". $rows[$i]['lng']."' /marker></markers>";
        //$rs->MoveNext(); //move on to the next record
        echo "</tr>";
 
 
    $rs->MoveNext(); //move on to the next record
 }
 
 
echo "</table>";
 
//close the connection and recordset objects freeing up resources
$rs->Close();
$conn->Close();
 
$rs = null;
$conn = null;
?>
But it is not working. Someone please help me

Thanks in advance

Kuttan