|
 |
|
ขอวิธี php แปลงข้อมูลใน mysql database ให้เป็น xml จะนำไปใช้กับ asp.net ครับ โดยให้เรียกจาก url ของ php |
|
 |
|
|
 |
 |
|
ดูตัวอย่างนี้ครับ
Code
CREATE TABLE `images` (
`ImageID` int(2) NOT NULL auto_increment,
`ItemID` varchar(50) NOT NULL,
`ImagePath` varchar(50) NOT NULL,
`Link` varchar(150) NOT NULL,
PRIMARY KEY (`ImageID`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=31 ;
--
-- Dumping data for table `images`
--
INSERT INTO `images` VALUES (1, 'Item 01', 'https://www.thaicreate.com/android/images/img01.gif', 'https://www.thaicreate.com/page-1.html');
INSERT INTO `images` VALUES (2, 'Item 02', 'https://www.thaicreate.com/android/images/img02.gif', 'https://www.thaicreate.com/page-2.html');
INSERT INTO `images` VALUES (3, 'Item 03', 'https://www.thaicreate.com/android/images/img03.gif', 'https://www.thaicreate.com/page-3.html');
INSERT INTO `images` VALUES (4, 'Item 04', 'https://www.thaicreate.com/android/images/img04.gif', 'https://www.thaicreate.com/page-4.html');
INSERT INTO `images` VALUES (5, 'Item 05', 'https://www.thaicreate.com/android/images/img05.gif', 'https://www.thaicreate.com/page-5.html');
Code (PHP)
<?php
header("Content-type:text/xml; charset=UTF-8");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
echo '<?xml version="1.0" encoding="utf-8"?>';
$objConnect = mysql_connect("localhost","root","root");
$objDB = mysql_select_db("mydatabase");
$strSQL = "SELECT * FROM images WHERE 1 ";
$objQuery = mysql_query($strSQL);
?>
<images>
<?
while($obResult = mysql_fetch_array($objQuery))
{
?>
<item>
<ImageID><?=$obResult["ImageID"];?></ImageID>
<ItemID><?=$obResult["ItemID"];?></ItemID>
<ImagePath><?=$obResult["ImagePath"];?></ImagePath>
<Link><?=$obResult["Link"];?></Link>
</item>
<?
}
?>
</images>
<?
mysql_close($objConnect);
?>
สามรถเรียกจาก URL ได้ครับ
ปกติ XML ใช้งานยากกว่าพวก JSON ครับ
|
 |
 |
 |
 |
Date :
2012-09-08 07:10:11 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 03
|