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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.