Fatal error: Call to a member function prepare() on a non-object in /var/www/op/DatosLibros.php on line 35
DatosLibros.php
Código:
<?php
class DatosLibros
{
private $cadenaConexion;
private $user;
private $password;
private $objetoConexion;
public function __construct($cadenaConexion,$user,$password)
{
$this->cadenaConexion=$cadenaConexion;
$this->user=$user;
$this->password=$password;
}
public function conectar ()
{
try
{
$this->objetoConexion= new PDO ($this->cadenaConexion,$this->user,$this->password);
$this->objetoConexion->setAttribute(PDO::ATTR_EARMODE,PDO::EARMODE_EXCEPTION);
}
catch (PDOException $ex)
{
echo "Se ha presentado un problema a la hora de conectar con la base de datos";
}
}
public function desconectar ()
{
$this->objetoConexion=null;
}
public function ejecutar ($strComando)
{
try
{
$ejecutar = $this->objetoConexion->prepare($strComando);
$ejecutar->execute();
$rows= $ejecutar->fetchAll();
}
catch (PDOException $ex)
{
throw $ex;
}
}
}
?>
Esta es la linea del error
Código:
$ejecutar = $this->objetoConexion->prepare($strComando);