Jump to content

Call to undefined method DOMDocument::dump_mem() during PHP/mysql wi googlemaps


phpnewby1918

Recommended Posts

Hello,

 

I've been following google maps with php/mysql turorial http://code.google.com/apis/maps/articles/phpsqlajax.html

 

I've come to my phpsqlajax_genxml.php file which as the google code has it like this:

 

<?php
require("phpsqlajax_dbinfo.php");

// Start XML file, create parent node
$doc = domxml_new_doc("1.0");
$node = $doc->create_element("markers");
$parnode = $doc->append_child($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 markers table
$query = "SELECT * FROM markers 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->create_element("marker");
  $newnode = $parnode->append_child($node);

  $newnode->set_attribute("name", $row['name']);
  $newnode->set_attribute("address", $row['address']);
  $newnode->set_attribute("lat", $row['lat']);
  $newnode->set_attribute("lng", $row['lng']);
  $newnode->set_attribute("type", $row['type']);
}

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

?>

 

I started with this but was getting errors at line 1!! I looked around abit on the net and found i should change

 

$doc = domxml_new_doc("1.0");

 

to this

 

$doc = new DOMDocument('1.0');

 

Then i got errors abour creating the elements, i looke on php.net and it looked like i needed to change

 

$node = $doc->create_element("markers");

$parnode = $doc->append_child($node);

$newnode->set_attribute("name", $row['name']);

 

 

To this:

 

$node = $doc->createElement('markers');

$parnode = $doc->appendChild($node);

$newnode->setAttribute ('name', $row['name']);

 

This at least got my code further down the page until the very last statment:

 

$xmlfile = $doc->dump_mem();

 

Here i'm getting this error "Fatal error: Call to undefined method DOMDocument::dump_mem()" along with "Warning: Cannot modify header information - headers already sent"

 

I havent even looked at the warning i just tried to fix the fatal error. Again i looked around the web and forums and php.net and thought maybe i need to set the value to "true" but it still got a fatal error.

 

I looked on php.net and in there examples for dump_mem() and they had the nodes set_attribute create_element and append_child.

 

Which confused me as that was what i used originally just following the google script and that got me the error right away "Fatal error to undefined method DOMDocument::create"

 

 

Can anybody point out whats going wrong? This is my script that I am using

 

<?php
require('connect.php');
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>phpsqlajax_genxml.php</title>
</head>

<body>
<?php
// Start XML file, create parent node
$doc = new DOMDocument('1.0');
$node = $doc->createElement('markers');
$parnode = $doc->appendChild($node);

// Select all rows in markers table
$query = "SELECT * FROM markers WHERE 1";
$result = mysql_query($query);
if (!$result) {
	die ('Invalid query: ' . mysql_error());
	}
header('Content-type: text/xml');

// Iterate through the rows, addind xml nodes for each
while ($row = mysql_fetch_assoc($result)) {
	// Add to XML document node

	$node = $doc->createElement('marker');
	$newnode = $parnode->appendChild($node);

	$newnode->setAttribute ('name', $row['name']);
	$newnode->setAttribute ('address', $row['address']);
	$newnode->setAttribute ('lat', $row['lat']);
	$newnode->setAttribute ('lng', $row['lng']);
	$newnode->setAttribute ('type', $row['type']);
	}

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

</body>

</html>

 

And the google code is on the link in posted in the messge also but this is theres both of which fail for Fatal errors either on the dump_mem() or new DOMDocument respecitvaley :

 

<?php
require("phpsqlajax_dbinfo.php");

// Start XML file, create parent node
$doc = domxml_new_doc("1.0");
$node = $doc->create_element("markers");
$parnode = $doc->append_child($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 markers table
$query = "SELECT * FROM markers 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->create_element("marker");
  $newnode = $parnode->append_child($node);

  $newnode->set_attribute("name", $row['name']);
  $newnode->set_attribute("address", $row['address']);
  $newnode->set_attribute("lat", $row['lat']);
  $newnode->set_attribute("lng", $row['lng']);
  $newnode->set_attribute("type", $row['type']);
}

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

?>

 

 

Thanks to anybody who can help me out  :wtf:

  • 3 months later...

Archived

This topic is now archived and is closed to further replies.

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