2
I’m trying to get the ID of a database with PHP. When 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 appears to me like this:
int(1)
array(1) {
[0]=>
array(1) {
["ID_PUBLICATION"]=>
string(1) "8"
}
}
From what I understand, it is returning the number of positions of the array and assigning the value to my $id_publication
, so it’s always 1.
It is possible to access this value that is returned from the bank?
Wow, it was fast! hahaha. Thank you @rray, that’s exactly what was wrong! I need to wait 8 minutes to score as response.
– Csorgo
@Csorgo Using the PDO? When returning only one records use the
fetch()
so you access the direct value (without the zero input)– rray
Thanks for the tip! I will adapt my code.
– Csorgo