Please help if you can. I am running PHP 5.0.3, Apatche 2.5 under Windows 2000. I wanted to start using the DOM. I downloaded php_domxml.dll fro PECL and put it in the ext directory. I added the following in php.ini file extension=php_domxml.dll

When I try to use it with the above changes being made I get the following error.

Call to undefined method domdocument::createElement() in F:\webserver\www\CG_255\A_FINAL\phpdom.php on line 21

Line 21 is
$root = $doc->createElement('root');

If you would like to see the entire code:

 <?php

if (!$conn =mysql_connect('localhost', 'root', 'dbontheweb')) {
	echo "Connection failed to the host 'localhost'.";
	exit();
}
if (!mysql_select_db("cg256")) {
	echo "Cannot connect to database 'test'";
	exit();
}

$table_id = 'user';
$query = "SELECT * FROM $table_id";
$dbresult = mysql_query($query, $conn);

// create a new XML document
$doc = new DOMDocument("1.0");

// create root node - note that you have to create the element and
// insert it into the document with two functions
$root = $doc->createElement('root');
$root = $doc->appendChild($root);

// process one row at a time
while($row = mysql_fetch_assoc($dbresult)) {

// add node for each row
$occ = $doc->createElement($table_id);
$occ = $doc->appendChild($occ);

// add a child node for each field
foreach ($row as $fieldname=>$fieldvalue) {
	$child = $doc->createTexNode($fieldname);
	$child = $occ->appendChild($value);
}
}

// get complete XML document
$xml_string = $doc->saveXML();
echo $xml_string;
?>

Regards,

Asfaw

    Did you restart the server? Did you create PHP INFO page to make sure it was installed? Did you get any errors when restarting the server?

      I have been using PHP/Apache/MySQL for over a year and it works. I want to start using DOM and it is not working as I indicated in my post. Other than that all of my pages work fine.

      What do I need to do to start using DOM other than what I described in my post?

      Thank you for your response.

      Asfaw

        Write a Reply...