Class shows values that do not correspond to the select

2

I'm using PHP / MySQL and in a class I have a function that should look for two maximum values in a single line and I have this code:

$sql = "SELECT max(id) as id, max(lote) as lote FROM sc_operac limit 1";
$bd = new ConexionDB();
$stmt = $bd->query($sql);
$row = $stmt->fetchColumn();
$registroVO = new OperacionesVO();
$registroVO->set_id( $row );
$registroVO->set_lote( $row );
print_r($registroVO);
return $registroVO;

But the print_r shows that both set_id and set_lote have the same value as the first one ( set_id ), why does this happen if they are two different values?

    
asked by Piropeator 29.09.2018 в 13:56
source

1 answer

2

The problem is that fetchColumn() returns the first data only. so to access the second data you have to use fetchColumn(1) .

$sql = "SELECT max(id) as id, max(lote) as lote FROM sc_operac limit 1";
$bd = new ConexionDB();
$stmt = $bd->query($sql);
$row = $stmt->fetchColumn();
$row2 = $stmt->fetchColumn(1);
$registroVO = new OperacionesVO();
$registroVO->set_id( $row );
$registroVO->set_lote( $row2 );
print_r($registroVO);
return $registroVO;
    
answered by 29.09.2018 / 14:40
source