0

what is wrong with this code:
when i do a $mysql = new sqlConnection("path.xml");

i get:
Warning: simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load external entity "path.xml" in /Applications/MAMP/htdocs/ebenezer/scripts/sqlconn.inc on line 11

Fatal error: Call to a member function children() on a non-object in /Applications/MAMP/htdocs/ebenezer/scripts/sqlconn.inc on line 13


the path.xml file is in the same directory as the phpclass

function __construct($fileName)
		{
			$xml = simplexml_load_file($fileName);
			foreach($xml->children() as $child)
  			{
  				if ($child->getName() == "server")
  					$this->server = $child;
  				if ($child->getName() == "user")
  					$this->user = $child;
  				if ($child->getName() == "pass")
  					$this->pass = $child;	
  				if ($child->getName() == "db")
  					$this->db = $child;	
  			}//end foreach loop
              }
2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by darkagn
0

You need to specify the relative path from the script calling the constructor, not from the class. For example, if your class and xml file are in the /classes folder, then you need to call $mysql = new sqlConnection("classes/path.xml");

I know that may seem strange considering that the class is in the same folder, but the path to a file is either relative to the script being run or absolute if specified in that way.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.