Error getting the bank's value

2

I'm trying to get the ID of a bank data with PHP. At the time of returning the value, it always comes as 1.

//Obtenho os valores por GET
$description = $_GET['DESC'];
$contentType = $_GET['TYPE'];
$content = $_GET['CONT'];

//Crio meu objeto de acesso ao banco e realizo a query
$dao = new DAO();
$result = $dao->select("SELECT ID_PUBLICATION FROM TB_PUBLICACOES_E_EVENTOS WHERE TXT_DESCRIPTION = :description AND TXT_TYPE = :contentType AND TXT_CONTENT = :content", Array(":description"=>$description, ":contentType"=>$contentType, ":content"=>$content));

//Atribuo o retorno (array) para um int 
$id_publication = (int) $result;

//Exibo os dois valores na tela
var_dump($id_publication);
var_dump($result);

The result looks like this to me:

int(1)
array(1) {
  [0]=>
  array(1) {
    ["ID_PUBLICATION"]=>
    string(1) "8"
  }
}

As I understand it, it is returning the number of array positions and assigning the value to my $id_publication , so it is always 1.

Is it possible to access this value that is returned from the bank?

    
asked by anonymous 29.08.2017 / 17:28

1 answer

2

$result is an array returned by a fetchAll() that way it always comes with a zero index. The correct way to access is:

$result[0]['ID_PUBLICATION'];
    
29.08.2017 / 17:33