0
Connectionclass
<?php
abstract class ConnectionClass {
protected function conecta(){
$dsn = "mysql:host=localhost; dbname = coletase";
$user = 'root';
$pass = '';
try{
$connectionPDO = new PDO($dsn, $user, $pass);
echo "foi";
return $connectionPDO;
}catch(PDOException $erro){
echo "DEU ERRO";
echo ($erro->getMessage());
}
}
}
My code:
<?php
include("conexao.php");
class PegaDadosClass extends ConnectionClass{
//Exibição dos dados dos locais em JSON
public function cospeJSON(){
$fetching=$this->conecta()->prepare("select * from local");
$fetching->execute();
$j=[];
$i=0;
while($fetch=$fetching->fetch(PDO::FETCH_ASSOC)){
$j[$i]=[
"id_local"=>$fetch['id_local'],
"latitude"=>$fetch['latitude'],
"longitude"=>$fetch['longitude'],
"descricao"=>$fetch['descricao'],
"titulo"=>$fetch['titulo'],
];
$i++;
}
header("Access-Control-Allow-Origin:*");
header("Content-type: application/json");
echo json_encode($j);
}
}
It returns me an empty array. The connection is established normally, but for some reason it returns me an empty array. Can you help me? I really have no idea why it didn’t work.
Instead of manually fetch each one tries to call this right after the run(),
$result = $fetching->fetchAll(PDO::FETCH_ASSOC);
and see what he brings– fajuchem