I have a php project in a structured main folder as follows:
- Container folder:
- Folder
config
- XML file
conexion.xml
- XML file
- Folder
php
- sub-folder
bd
- PHP file
conexionbd.php
- PHP file
- PHP file
consultas.PHP
- sub-folder
- HTML file
index.html
- Folder
conexion.xml
<?xml version="1.0"?>
<conexion>
<servidor>localhost</servidor>
<usuario>
<usuario_bd>usuario</usuario_bd>
<contrasena_bd>contrasena</contrasena_bd>
</usuario>
<bd>nombre_bd</bd>
</conexion>
conexionbd.php
<?php
if (file_exists("../../config/conexion.xml")) {
$archivo_xml= simplexml_load_file("../../config/conexion.xml");
/*Se asigna los valores del archivo XML a las variables PHP*/
$servidor=$archivo_xml->servidor;
$usuario_bd=$archivo_xml->usuario->usuario_bd;
$contrasena_bd=$archivo_xml->usuario->contrasena_bd;
$bd=$archivo_xml->bd;
try{
$conn= new mysqli($servidor,$usuario_bd,$contrasena_bd,$bd);
echo "Conectado";
}catch(Exception $e){
echo $e;
}
}else{
echo "el archivo no existe";
}
?>
If I run the application until here the result is the following:
consultas.php
<?php
include("bd/conexionbd.php");
?>
At the time of running the application here it shows me the following:
Why is it that the include("bd/conexionbd.php")
does not detect the XML file and how can I fix it?