0

This project is written on PHP using PDO connection, with a class, and is readed by another PHP file in that PHP I use:

include_once

this is de issue code:

 <?php
//extension de conexion a base de datos usando PDO
//leemos el archivo ini
$db = parse_ini_file(realpath('./conexion.ini'));
class BaseDatos{
//asignamos variables
    private $dsn = $db['name'];//<--this is the line of the problems
    private $user = $db['user'];
    private $password = $db['pass'];
    private $host = $db['host'];
    public $conn;
    public function obtenerConexion(){
        $this-> conn = null;
        try{
            $this -> conn = new PDO("mysql:host=" . $this->host . ";dbname=" . $this->dsn, $this->user, $this->password);
            $this->conn->exec("set names utf8");
        }
        catch(PDOException $e){
            echo 'Connection failed:' . $e->getMessage();
        }
    return $this->conn;
    }
}?>

And this is the Include code:

<?php// cabezales
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
// se incluyen objetos de base de datos
include_once '../configuracion/ConnDB.php';
include_once '../objetos/usuarios.php';
// instanciacion de la base de datos y de los objetos
$database = new Database();
$db = $database->getConnection();
 // inicializacion de los objetos
$usuarios = new Usuarios($db);
 // query Usuarios
$stmt = $usuarios->read();
$num = $stmt->rowCount();

I check the code for missing semicolon's or braces, that is the most popular error on this cases,but I don't find anything wrong, probably that means to me I'm missing some syntax validation. I edited the post, the problem is that the class lose the scope of $db, I know I'm doing something wrong, but what is. Thanx for all your help.

0 Answers0