The wonderful non-intuitive php include statement



Ok .. I have some classes set up to do some database queries and what
not. The database configuration is an XML file. Now I need to include
this class in a few pages, in different directories. Here is an
example of the class.

class foo {
private $xml;

function foo() {
$this->xml = simplexml_load_file('config/dbconfig.xml);
}

public function dbStuff() {
//do some db stuff
}

etc......
}


I am using apache which has php set up as a module. This class (which
resides 2 directories deep e.g htdocs/classes/foo) works fine in
main.php which resides in htdocs. But if I include this class in
another php file which is in a different directory .... say htdocs/
forums I get this type of error:

Warning: simplexml_load_file() [function.simplexml-load-file]: I/O
warning : failed to load external entity "config/dbconfig.xml"

I tried using set_include_path(), which I could not get to work right,
and I also tried to set 'include_path' in php.ini which also did not
work. PHP include seems to work very non-intuitive which is driving me
nuts. They really need to implement this a little better. I really
don't see why the simplexml_load_file works in htdocs/classes/foo and
not htdocs/forums.

.



Relevant Pages

  • Re: The wonderful non-intuitive php include statement
    ... The database configuration is an XML file. ... I am using apache which has php set up as a module. ... main.php which resides in htdocs. ...
    (comp.lang.php)
  • Re: How to insert UTF8 into mysql from PHP
    ... It works correctly for ascii text in XML file but not for non-ascii ones. ... If $insert is written to a file (using fwrite in PHP), the characters are correct. ...
    (comp.lang.php)
  • Re: The wonderful non-intuitive php include statement
    ... The database configuration is an XML file. ... I am using apache which has php set up as a module. ... Important to remember is that the current working directory normally is the path of the script that got started by the request, and will NOT change in other included files. ...
    (comp.lang.php)
  • Re: creating XML with embedded PHP
    ... >me to embed PHP into an xml file like I would do to an HTML file in order to ... however the apache server does not realize that it's PHP ... Depends whether you count this as "modifying" the server, ...
    (comp.lang.php)
  • Re: Using PHP to generate HTML from the contents of an XML file?
    ... >> XML file, and use the contents of this file to generate a HTML page? ... >> I need to implement this using PHP and have very little experience. ... My experience is that XSLT is the most straightforward way to produce ... SAX parser - at least as soon as the transformation is just a bit more ...
    (comp.lang.php)