Click here to Skip to main content
14,239,615 members
Rate this:
Please Sign up or sign in to vote.
See more:
Dear reader,

I am trying to read a XML file (made by an application via c#) into PHP.

Whatever I try it won't work

What I have tried:

This is the code;

<?php 

error_reporting(E_ALL);
ini_set('display_errors', 1);

$myXMLData = $_GET["C:\ProgramData\DS\Config.xml"];
$xml=simplexml_load_string($myXMLData);


$connectionInfo = array( "Database"=> $xml->DatabaseConnection[0]->InitialCatalog, "UID"=> $xml->DatabaseConnection[0]->UserID, "PWD"=>$$xml->DatabaseConnection[0]->Password);
$conn = sqlsrv_connect( $xml->DatabaseConnection[0]->DataSource, $connectionInfo);

if( $conn ) {
     echo "Connection established. <br/><br/>
	 
	
	 ";
}else{
     echo "Connection could not be established.<br /><br>";
     die( print_r( sqlsrv_errors(), true));
	 print_r(PDO::getAvailableDrivers());
} 

?>


This is the erorr code;

Notice: Undefined index: C:\ProgramData\DS\Config.xml in B:\_Websites\testpage.php on line 68

Notice: Trying to get property of non-object in B:\_Websites\testpage.php on line 72

Notice: Trying to get property of non-object in B:\_Websites\testpage.php on line 72

Notice: Trying to get property of non-object in B:\_Websites\testpage.php on line 72

Notice: Trying to get property of non-object in B:\_Websites\testpage.php on line 72

Notice: Undefined variable: in B:\_Websites\testpage.php on line 72

Notice: Trying to get property of non-object in B:\_Websites\testpage.php on line 72

Notice: Trying to get property of non-object in B:\_Websites\testpage.php on line 72

Notice: Trying to get property of non-object in B:\_Websites\testpage.php on line 73

Notice: Trying to get property of non-object in B:\_Websites\testpage.php on line 73
Connection could not be established.

Array ( [0] => Array ( [0] => IMSSP [SQLSTATE] => IMSSP [1] => -1 [code] => -1 [2] => Invalid option was passed to sqlsrv_connect. [message] => Invalid option was passed to sqlsrv_connect. ) )
Posted
Comments
Anurag Gandhi 10-Jul-19 11:54am
   
What is the structure of your xml file. Please post your xml file.
It seems DatabaseConnection is not an array but you are trying to read it as array.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100