I'm doing a query SQL
in PHP
using MVC
. I'm doing a function which has a parameter and this is used in the query SQL
. This is the code and up to this point it works for me.
public function miFuncion($u){
$stm = $this->pdo->prepare("SELECT T.tare_id AS tarea_id, TI.tick_codi AS codigo, TI.tick_nom AS nombre_ticket, PI.piez_nom AS pieza, T.num_pieza AS cantidad_piezas, PR.prod_nom AS producto,concat(US.usua_nom,' ',US.usua_ape) AS usuario , ES.esta_nom AS estado, EM.empr_nom AS cuenta, T.tare_asig AS fecha_de_asignacion, T.tare_entr AS fecha_de_entrega, MAX(HI.hist_cod) AS cantidad_ajustes
FROM tarea T
INNER JOIN pieza PI ON T.piez_id = PI.piez_id
INNER JOIN producto PR ON T.prod_id = PR.prod_id
INNER JOIN usuario US ON T.user_id = US.usua_id
INNER JOIN ticket TI ON T.tick_id = TI.tick_id
INNER JOIN estados ES ON T.esta_id = ES.esta_id
INNER JOIN empresa EM ON TI.empr_id = EM.empr_id
INNER JOIN historial HI ON T.tare_id = HI.tare_id
WHERE T.user_id = 11
GROUP BY T.tare_id
ORDER BY tarea_id ASC");
$stm->execute();
return $stm->fetchAll(PDO::FETCH_OBJ);
}
When I replace in the line of WHERE
the value of 11 by the variable $u
This throws me the following error
SQLSTATE [42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'GROUP BY T.tare_id ORDER BY ASC_work ASID' at line 11
The value of the parameter is reaching the function, I have checked it with an'echo'. But when replacing the value of 11 with the variable $ u the query does not work for me anymore.