Fatal error: Call to a member function query() on a non-object in
Boa noite,
bom não entendo nada de php apenas sou fuçado,
estou tentando "listar" o conteudo do db com pdo
e está me retornando o seguinte erro:
Fatal error: Call to a member function query() on a non-object in C:\WebServer\freelancer\freelancer\incs\fotos.php on line 10Call Stack#TimeMemoryFunctionLocation10.0051276088{main}( )..\index.php:020.0107300024FotosDAO->getAll( )..\index.php:104
ta no index.php
<?php
$fotosDAO = new fotosDAO();
$results = $fotosDAO->getAll();
foreach($results as $post) {
echo $post->getfotoNOME() . '<br />';
echo '<br />';
}
?>
fotosCON.php
<?php
function conectar()
{
define('HOST', 'mysql:host=localhost;dbname=teste');
define('USER', 'user');
define('PASS', 'senha');
try
{
$dbh = new PDO(HOST, USER, PASS);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}catch(PDOException $e)
{
echo
(
'<div class="alert alert-error">
Erro:' . $e->getMessage(). ';(
</div>'
);
}
return $dbh;
function desconectar(){
$this->conectar = null;
}
}fotos.php
<?php
include_once('incs/fotos.php');
include_once('incs/fotosCON.php');
class FotosDAO {
private $dbh;
public function getAll() {
$statement = $this->dbh->query(
'SELECT * FROM dpfotos'
);
return $this->processResults($statement);
}
private function processResults($statement) {
$results = array();
if($statement) {
while($row = $statement->fetch(PDO::FETCH_OBJ)) {
$post = new Foto();
$post->setfotoID($row->fotoID);
$post->setfotoNOME($row->fotoNOME);
$post->setfotoPOS($row->fotoPOS);
$results[] = $post;
}
}
return $results;
}
}
?>Discussão (12)
Carregando comentários...