La sentencia fetchAll(PDO::FETCH_OBJ) No imprime datos
Publicado por Jimena (1 intervención) el 06/09/2020 03:09:25
Ayudaaa por favor, tengo el siguiente código php para poder mostrar los valores de una tabla, sin embargo me sale: array (size=0)
empty
Obviamente tengo datos dentro de la tabla.
POR OTRO LADO TENGO EL INDEX.PHP
empty
Obviamente tengo datos dentro de la tabla.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?php
class Crud
{
protected $tabla;
protected $conexion;
protected $wheres = "";
protected $sql = null;
public function __construct($tabla = null) {
$this->conexion = (new Conexion())->conectar();
$this->tabla = $tabla;
}
public function get()
{
try{
$this->sql = "SELECT * FROM {$this->tabla} {$this->wheres}";
$sth = $this->conexion->prepare($this->sql);
$sth->execute();
return $sth->fetchAll(PDO::FETCH_OBJ);
} catch (Exception $exc)
{
echo $exc->getTraceAsString();
}
}
}
POR OTRO LADO TENGO EL INDEX.PHP
1
2
3
4
5
6
7
8
9
10
11
12
<?php
require_once './bin/modelo/conexion.php';
require_once './bin/persistencia/crudEmpresa.php';
$crud = new Crud("empresa");
$lista = $crud->get();
echo"<pre>";
var_dump($lista);
echo"</pre>";
Valora esta pregunta


0