Comments on: Convert MySQL to XML using PHP /coding/mysql-to-xml-php/ Webdevelopment Blog Sat, 14 May 2016 13:11:47 +0000 hourly 1 https://wordpress.org/?v=4.5.15 By: felix /coding/mysql-to-xml-php/#comment-1591 Sat, 14 May 2016 13:11:47 +0000 /?p=4#comment-1591 my code is
<?php
//database configuration
$config['mysql_host'] = "localhost";
$config['mysql_user'] = "root";
$config['mysql_pass'] = "";
$config['db_name'] = "mansion";
$config['table_name'] = "property";

//connect to host
mysql_connect($config['mysql_host'],$config['mysql_user'],$config['mysql_pass']);
//select database
mysql_select_db($config['db_name']) or die( "Unable to select database");
$xml = "”;
$root_element = $config[‘table_name’].”s”;
$xml .= “”;
//select all items in table
$sql = “SELECT * FROM “.$config[‘table_name’];

$result = mysql_query($sql);
if (!$result) {
die(‘Invalid query: ‘ . mysql_error());
}

if(mysql_num_rows($result)>0)
{
while($result_array = mysql_fetch_assoc($result))
{
$xml .= “”;

//loop through each key,value pair in row
foreach($result_array as $key => $value)
{
//$key holds the table column name
$xml .= “”;

//embed the SQL data in a CDATA element to avoid XML entity issues
$xml .= “”;

//and close the element
$xml .= “”;
}

$xml.=””;
}
}
//close the root element
$xml .= “”;

//send the xml header to the browser
header (“Content-Type:text/xml”);

//output the XML data
echo $xml;
?>

Untitled Document

when i run this code……I get the error message
This page contains the following errors:

error on line 1 at column 1418: error parsing attribute name
Below is a rendering of the page up to the first error.
plzz…….help…..its very urgent

]]>
By: Adesh Shah /coding/mysql-to-xml-php/#comment-1590 Wed, 30 Mar 2016 05:39:07 +0000 /?p=4#comment-1590 Very good explanation, but it would be really great if you guys update the mysql command with PDO or mysqli. As I tried to run following example and it showed my that mysql is depreciated.

Thanks,
Adesh

]]>
By: Dipal Modi /coding/mysql-to-xml-php/#comment-1589 Wed, 16 Mar 2016 17:00:39 +0000 /?p=4#comment-1589 Hello,
I have an error for following code in $xml .= “”;

<?php

//Database configuration
$config['mysql_host'] = "localhost";
$config['mysql_user'] = "root";
$config['mysql_pass'] = "dipalmodi";
$config['db_name'] = "xml";
$config['table_name'] = "my_data";

//connectto host
mysql_connect($config['mysql_host'],$config['mysql_user'],$config['mysql_pass']);

//select database
@mysql_select_db($config['db_name']) or die( "Unable to select database");

$xml = "”;
$root_element = $config[‘table_name’].”s”; //my_data
$xml .= “”;

//select all items in table
$sql = “select * from “.$config[‘table_name’];

$result = mysql_query($sql);
if(!$result)
{
die(‘Invalid Query: ‘ .mysql_error());
}

if(mysql_num_rows($result)>0)
{
while($result_array = mysql_fetch_assoc($result))
{
$xml. = “”;

//loop through each key, value pair in row
foreach($result_array as $key => $value)
{
//$key holds the table column name
$xml.=””;

//embed the SQL data in a CDATA element to avoid XML entity issues
$xml.= “”;

//and close the element
$xml.=””;
}
$xml.=””;
}
}

//close the root element
$xml.=””;

//send the xml header to the browser
header(“Content-Type:text/xml”);

//output the xml data
echo $xml;

?>

please reply me ASAP.

]]>
By: Lemosys /coding/mysql-to-xml-php/#comment-1584 Tue, 18 Aug 2015 06:03:20 +0000 /?p=4#comment-1584 It’s really knowledgeable post for programmer. Nicely explained by developer with example.currently i am working on oracle data base so ,it’s can applicable for other database like oracle,my access .

]]>
By: nakul /coding/mysql-to-xml-php/#comment-1583 Sat, 15 Aug 2015 11:13:55 +0000 /?p=4#comment-1583 please help my output is coming in CDATA. I want to remove that

MY CODE IS:

<?php

$config['db_name'] = "algo_marketing";
$config['table_name'] = "trade";

//connect to host
mysql_connect($config['mysql_host'],$config['mysql_user'],$config['mysql_pass']);
//select database
@mysql_select_db($config['db_name']) or die( "Unable to select database");

$xml = "”;
$root_element = $config[‘table_name’].”s”;
$xml .= “”;

//select all items in table
$sql = “SELECT * FROM “.$config[‘table_name’];

$result = mysql_query($sql);
if (!$result) {
die(‘Invalid query: ‘ . mysql_error());
}

if(mysql_num_rows($result)>0)
{
while($result_array = mysql_fetch_assoc($result))
{
$xml .= “”;

//loop through each key,value pair in row
foreach($result_array as $key => $value)
{
//$key holds the table column name
$xml .= “”;

//embed the SQL data in a CDATA element to avoid XML entity issues
$xml .= “”;

//and close the element
$xml .= “”;
}

$xml.=””;
}
}

//close the root element
$xml .= “”;

//send the xml header to the browser
header (“Content-Type:text/xml”);

//output the XML data
echo $xml;
?>

]]>
By: Kendo /coding/mysql-to-xml-php/#comment-1578 Tue, 28 Apr 2015 16:10:24 +0000 /?p=4#comment-1578 Nice script. But how to save the xml view in xml files in server ?

]]>
By: Aamir /coding/mysql-to-xml-php/#comment-1575 Fri, 20 Mar 2015 14:47:51 +0000 /?p=4#comment-1575 Dear Reader,

This helped me. Just put output into a variable then add this code.

$myfile = fopen(“newfile.xml”, “w”) or die(“Unable to open file!”);
fwrite($myfile, $xml);
fclose($myfile);

it will generate every time updated XML file when will refresh php.

]]>
By: PHPNewb /coding/mysql-to-xml-php/#comment-1572 Mon, 05 Jan 2015 01:50:27 +0000 /?p=4#comment-1572 I don’t see the “example” for how to save to a file. I’ve tried several methods without success. Pls advise. Thanks

]]>
By: Muhammad Bilal /coding/mysql-to-xml-php/#comment-1571 Fri, 19 Dec 2014 14:42:07 +0000 /?p=4#comment-1571 Sir not work on google chrome and have this error

“This XML file does not appear to have any style information associated with it. The document tree is shown below.”

i am new in XML
Help me

]]>
By: MightyWebdev /coding/mysql-to-xml-php/#comment-1569 Sat, 08 Nov 2014 11:36:01 +0000 /?p=4#comment-1569 Hi Jeff, try it out. In PHP variables in a string in quotation marks are replaced by the value of that variable.

]]>