I'm using PHP/MySQL and in a class I have a function that should search for two max 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_lot have the same value of the first one ( set_id ), why does this happen if they are two different values?
The problem is that it
fetchColumn()
returns the first data only. so to access the second data you have to usefetchColumn(1)
.