반응형
내 웹 사이트에 MySQL 데이터베이스가 있는데 PHP를 통해 테이블에있는 다음 열의 XML 출력을 얻는 방법을 알고 싶습니다.
해결 방법
mysql_connect('server', 'user', 'pass');
mysql_select_db('database');
$sql = "SELECT udid, country FROM table ORDER BY udid";
$res = mysql_query($sql);
$xml = new XMLWriter();
$xml->openURI("php://output");
$xml->startDocument();
$xml->setIndent(true);
$xml->startElement('countries');
while ($row = mysql_fetch_assoc($res)) {
$xml->startElement("country");
$xml->writeAttribute('udid', $row['udid']);
$xml->writeRaw($row['country']);
$xml->endElement();
}
$xml->endElement();
header('Content-type: text/xml');
$xml->flush();
산출:
<?xml version="1.0"?>
<countries>
<country udid="1">Country 1</country>
<country udid="2">Country 2</country>
...
<country udid="n">Country n</country>
</countries>
참조 페이지 https://stackoverflow.com/questions/5112282
반응형
'MySql' 카테고리의 다른 글
MySQL id가 일치하면 mysql에서 행 선택 (0) | 2020.10.17 |
---|---|
MySQL에서 JSON 값이 비어 있는지 확인 하시겠습니까? (0) | 2020.10.17 |
MySQL mysql에서 삭제 캐스케이드를 어떻게 사용합니까? (0) | 2020.10.17 |
MySQL SQL 쿼리 : 큰 테이블 간의 내부 조인 최적화 (0) | 2020.10.17 |
MySQL Windows의 Python 3.6에 mysqlclient 설치 (0) | 2020.10.17 |
댓글