0

データベースから XML を作成しようとしましたが、WampServer で PHP コードを実行するとエラーが発生します。

XML Parsing Error: junk after document element
Line Number 2, Column 1:<font size='1'><table class='xdebug-error' 
dir='ltr' border='1' cellspacing='0' cellpadding='1'>

code.google からの私のコード:

{<?php

require("phpsqlajax_dbinfo.php");    
// Start XML file, create parent node    
$doc = new DOMDocument('1.0', 'iso-8859-1');    
$node = $doc->createElement("place");    
$parnode = $doc->appendChild($node);

// Opens a connection to a MySQL server    
$connection=mysql_connect (localhost, $username, $password);    
if (!$connection) {    
  die('Not connected : ' . mysql_error());
}

// Set the active MySQL database    
$db_selected = mysql_select_db($database, $connection);    
if (!$db_selected) {    
  die ('Can\'t use db : ' . mysql_error());    
}

// Select all the rows in the place table    
$query = "SELECT * FROM place WHERE 1";    
$result = mysql_query($query);    
if (!$result) {    
  die('Invalid query: ' . mysql_error());    
}

header("Content-type: text/xml");

// Iterate through the rows, adding XML nodes for each    
while ($row = mysql_fetch_assoc($result)){

  // ADD TO XML DOCUMENT NODE    
  $node = $doc->createElement("place");    
  $newnode = $parnode->appendChild($node);    
  $newnode->set_attribute("place_id", $row['place_id']);    
  $newnode->set_attribute("p_name", $row['p_name']);    
  $newnode->set_attribute("lat", $row['lat']);    
  $newnode->set_attribute("lng", $row['lng']);    
  $newnode->set_attribute("addr", $row['addr']);    
  $newnode->set_attribute("tel", $row['tel']);    
  $newnode->set_attribute("category", $row['category']);    
  $newnode->set_attribute("description", $row['description']);
}

$xmlfile = $doc->dump_mem();    
echo $xmlfile;

?>

これは表です:

place_id(int),    
p_name(varchar),    
lat(float),    
lng(float),    
addr(varchar),    
tel(int),    
category(varchar),    
description(varchar)
4

2 に答える 2

0

Googleマップのphp/mysqlチュートリアルでも同じ問題がありました。localhost ex $connection=mysql_connect ('localhost', $username, $password); に一重引用符を付けると機能することがわかりました。

于 2013-10-01T12:16:02.863 に答える