View Full Version : fail to open

08-20-2007, 01:47 PM
hi all,

i tried to create an XML file by selecting data direct from database (MySQL) and wanting to name the XML file under .xml format so that it can be read by vb.net later on in another application. but i couldnt get to save the xml file. (T_T). so here is my php code follow by the error..

// create a new XML document
$doc = new DomDocument('1.0');

// create root node
$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 = $root->appendChild($occ);

// add a child node for each field
foreach ($row as $fieldname => $fieldvalue) {

$child = $doc->createElement($fieldname);
$child = $occ->appendChild($child);

$value = $doc->createTextNode($fieldvalue);
$value = $child->appendChild($value);

} // foreach
} // while

// get completed xml document
$doc->formatOutput = true;
$test1 = $doc->saveXML();
echo $test1;

and the error:

<b>Fatal error</b>: Call to a member function save() on a non-object in <b>c:\Inetpub\wwwroot\testxml.php</b> on line <b>49</b>

please help me. thank you in advance.

08-20-2007, 03:43 PM
$test1 is not the name of the object you created, $doc is. $test1 is a string that you assigned two lines above the call to the save() member function.

08-21-2007, 04:42 AM

thanks for replying..^^

well even i change, the error is still the same. im not sure what's wrong. ive enable the safe mode in the php.ini. still i couldnt get it. huhu (T_T)
// get completed xml document
$doc->formatOutput = true;
$test1 = $doc->saveXML();
//echo $test1;

i even tried below and the error is " Warning: DOMDocument::save(C: est1.xml) [function.save]: failed to open stream: Invalid argument in c:\Inetpub\wwwroot\testxml.php on line 47 "
// get completed xml document
$doc->formatOutput = true;
$test1 = $doc->save("C:\test1.xml");

08-21-2007, 05:28 AM
In looking closely at the latest error message, do one of the following -


$doc->save("C:/test1.xml");Windows accepts either type of slash, but to use a \ you must escape it to make it a literal \

08-22-2007, 12:50 PM

tried tht and still it didnt work. (T_T) instead the error message is

Warning: DOMDocument::save(C:\test1.xml) [function.save]: failed to open stream: Permission denied in c:\Inetpub\wwwroot\testxml.php on line 48

hmm...do u think the code save is to resave an existing file?? or it can be use to save a new file as well??

08-22-2007, 02:10 PM
The message indicates a permissions problem. Make sure that the c:\Inetpub folder and the c:\Inetpub\wwwroot folder have at least read and write privileges for the IIS user account - IUSR_your_machine_name_here. Also, make sure that the php.ini doc_root = parameter has been set correctly. See the following from the PHP installation instructions for IIS -

* The IIS user (usually IUSR_MACHINENAME) needs permission to read
various files and directories, such as php.ini, docroot, and the
session tmp directory.
* Be sure the extension_dir and doc_root PHP directives are
appropriately set in php.ini. These directives depend on the system
that PHP is being installed on. In PHP 4, the extension_dir is
extensions while with PHP 5 it's ext. So, an example PHP 5
extensions_dir value is "c:\php\ext" and an example IIS doc_root
value is "c:\Inetpub\wwwroot".Reboot your computer to get any changes made to php.ini to take effect.

Also, is there a specific reason why you are using IIS? If you don't need to use IIS, Apache is a much better choice for using PHP with.

08-23-2007, 09:43 AM

yay!! it works....ohoo..so tht is "permission" evryone been talkin about. God!
thanks alot CFMaBiSmAd !!! \(^o^)/