Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7

Thread: fail to open

  1. #1
    New to the CF scene
    Join Date
    Aug 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    fail to open

    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;
    $test1->save("C:/test1.xml");
    ?>


    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.

  • #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,151
    Thanks
    2
    Thanked 335 Times in 327 Posts
    $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.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #3
    New to the CF scene
    Join Date
    Aug 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hi,

    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;
    $doc->save("C:\test1.xml");


    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");
    Last edited by alvon; 08-21-2007 at 04:48 AM. Reason: forgot the error message

  • #4
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,151
    Thanks
    2
    Thanked 335 Times in 327 Posts
    In looking closely at the latest error message, do one of the following -
    PHP Code:
    $doc->save("C:\\test1.xml"); 
    or
    PHP Code:
    $doc->save("C:/test1.xml"); 
    Windows accepts either type of slash, but to use a \ you must escape it to make it a literal \
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #5
    New to the CF scene
    Join Date
    Aug 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hi,

    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??

  • #6
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,151
    Thanks
    2
    Thanked 335 Times in 327 Posts
    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.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #7
    New to the CF scene
    Join Date
    Aug 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    waaa......!!!

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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •