I can not find a POO class in php

0

I am making a connection to a database through POO and it is throwing me an error that the "Connection" class does not find me, but I have it added as inheritance in the class "ReturnsProducts".

I have 3 php files.

1) The one that makes the connection with the called BBDD (Conexion_BBDD_con_clases_poo.php):

require "datosconexion.php";
 class Conexion{
    protected $conexion_db;

        function __construct(){

            $this->conexion_db=new mysqli(DB_HOST, DB_USUARIO, DB_CONTRA, DB_NOMBRE);

                if ($this->conexion_db->connect_errno){
                    echo "No se pudo establecer conexion con la base de datos" . $this->conexion_db->connect_error;
                return;
    }
    $this->conexion_db->set_charset(DB_CHARSET);
}

}

The container of the information of the called BBDD (datosconexion.php):

define('DB_HOST', 'localhost');
define('DB_USUARIO', 'root');
    define('DB_CONTRA', '');
        define('DB_NOMBRE', 'pruebas');
            define('DB_CHARSET', 'uft8');

3) The one that returns the products of the query (returns_products.php)

require "datosconexion.php";
                    //heredando todo de la clase Conexion
class DevuelveProductos extends Conexion{                               /* Clases Conexion ---> DevuelveProductos */

function __construct(){
    parent::__construct(); //Llamando constructor de la clase padre(CONEXION), CONECTANDO CON LA BASE DE DATOS
}
public function get_productos(){
    $resultado=$this->conexion_db->query('SELECT * FROM PRODUCTOS'); //CONSULTA SQL
    $productos=$resultado->fetch_all(MYSQLI_ASSOC); //ALMACENANDO RSULTADOS DE LA CONSULTA SQL
    return $productos; //NUNCA OLVIDAR EL RETURN, NOS ARROJA EL ARRAY
}

}

and the index:

<?php 
//Incluyendo los archivos antes hechos
require "devuelve_productos.php";
//creando instancias de la clase devuelve_productos, y se crea para que se ejecute dentro de la clase DevuelveProductos()
$productos=new DevuelveProductos();
//Fin instancia
$array_productos=$productos->get_productos();

? >                     Html              

foreach ($array_productos as $elementofila){
    echo "<table><tr><td>";
    echo $elementofila["CÓDIGOARTÍCULO"] . "</td><td>";
    echo $elementofila["NOMBREARTÍCULO"] . "</td><td>";
    echo $elementofila["SECCIÓN"] . "</td><td>";
    echo $elementofila["PRECIO"] . "</td><td>";
    echo $elementofila["FECHA"] . "</td><td>";
    echo $elementofila["IMPORTADO"] . "</td><td>";
    echo $elementofila["PAÍSDEORIGEN"] . "</td><td></tr></table>";

        echo "<br>";
        echo "<br>";

}   

 ?>

 

and this error is showing up:

And the error is happening on line 4, which is:

  

class ReturnsProducts extends Connection {

of the file returns_products.php

    
asked by Victor Escalona 09.04.2018 в 03:00
source

1 answer

1

I solved it, I had 2 errors:

First error:

I was not including Conexion_BBDD_con_clases_poo.php in devuelve_productos.php Therefore I was throwing the error that the "Connection" class was not found

Second error: The columns of the database looked like this:

And I was throwing the error [INDEX ERROR ...]

The solution was to remove the existing accents in the columns, Passing from

  

"C OR DIGOART Í ASS -

Removing the accents from each column resolved the problem completely.

    
answered by 09.04.2018 в 04:11