Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
<?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.
Robin Uters 19-Jul-19 2:43am    
Hi Anurag,

Herewith the XML code

Config:
$xmldata = simplexml_load_file("C:\ProgramData\ARAS\EasyVisitor\Config\Config.xml") or die("Failed to load");
$XML_SQL_DataSource = $xmldata->DatabaseConnection[0]["DataSource"];
$XML_SQL_InitialCatalog = $xmldata->DatabaseConnection[0]["InitialCatalog"];
$XML_SQL_UserID = $xmldata->DatabaseConnection[0]["UserID"];
$XML_SQL_Password = $xmldata->DatabaseConnection[0]["Password"];

XML Code:
Hide   Copy Code
<?xml version="1.0" encoding="utf-8"?><Config><DatabaseConnection DataSource="SQLSERVER" InitialCatalog="SQLDATABASE" UserID="SQLUSER" Password="SQLPASSWORD" /></Config>


PHP Code:
Hide   Copy Code
<?php error_reporting(E_ALL);ini_set('display_errors', 1);$connectionInfo = array( "Database"=>$XML_SQL_InitialCatalog, "UID"=>$XML_SQL_UserID, "PWD"=>$XML_SQL_Password);$conn = sqlsrv_connect( $XML_SQL_DataSource, $connectionInfo);if( $conn ) {     echo "Connection established. <br/><br/>	 	 SQL Server: 	$XML_SQL_DataSource <br>	 SQL Database: 	$XML_SQL_InitialCatalog <br>	 SQL Username: 	$XML_SQL_UserID <br>	 SQL Password: 	".md5($XML_SQL_Password)." (For Secure password is encrypted.)<br> 	 ";}else{     echo "Connection could not be established.<br /><br>";     die( print_r( sqlsrv_errors(), true));	 print_r(PDO::getAvailableDrivers());}  ?>


Current Error code:
Connection could not be established.

Array ( [0] => Array ( [0] => IMSSP [SQLSTATE] => IMSSP [1] => -33 [code] => -33 [2] => Invalid value type for option Database was specified. String type was expected. [message] => Invalid value type for option Database was specified. String type was expected. ) )

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900