Jump to content

Help needed Generate XML from MSSQL


kuttan939

Recommended Posts

Hi

 

I am new to PHP. I am in a new project to integrate google map. I need to generate an XML file from MSSQL database. I have written a PHP code as below, but it is not working.....

<?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>";
                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;
?>

 

Someone please help

 

Thanks in advance

 

Kuttan

Link to comment
https://forums.phpfreaks.com/topic/114620-help-needed-generate-xml-from-mssql/
Share on other sites

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.