I have the pattern singleton
and a class ticket
:
public function registrar(){
//me conecto a la bd
$conexion = Conexion::singleton_conexion();
try{
$conexion->beginTransaction();
$queryid="select comprobante from identificadores;";
$array=$conexion->query($queryid);
foreach($array as $a){
$id = $a['comprobante'];
}
$qnuevoid="UPDATE identificadores SET comprobante=".++$id.";";
$conexion->query($qnuevoid);
$queryticket="insert into despensa.ticket (idticket, fecha, total,vuelto)
values (".$id.",'".$this->fecha."',56,88);";
$conexion->query($queryticket);
$conexion->commit();
}catch(Exception $e){
$conexion->rollBack();
echo "Fallo: " . $e->getMessage();
}
}
}
The fact is that I want to know how to access the value of a select mysql query with PDO to avoid this:
foreach($array as $a){
$id = $a['comprobante'];
}
I think it's not the right way!