I need to pass a dynamic variable for OFFSET inside the query. I have searched and found out that since Mysql 5.6 this is supported. I am using version 5.6.25 but I still get a syntax error.
Here is my code.
try {
$DBH = connect_sesiones();
$SMT = $DBH->prepare("
SELECT msg.id AS msgId,
msg.id_emisor AS msgIdEmisor,
msg.id_receptor AS msgIdReceptor,
msg.mensaje AS msgMensaje,
msg.leido AS msgLeido,
msg.fecha AS msgFecha,
us.nombre AS userNombre,
us.apellido AS userApellido
FROM (mensajes msg
INNER JOIN usuarios us ON (CASE WHEN msg.id_emisor = :sessionUserId THEN us.id = msg.id_receptor WHEN msg.id_receptor = :sessionUserId THEN us.id = msg.id_emisor END))
WHERE (msg.id_emisor = :sessionUserId AND msg.id_receptor = :contactId)
OR
(msg.id_emisor = :contactId AND msg.id_receptor = :sessionUserId)
LIMIT 8, OFFSET :offset
");
$SMT->bindParam (':sessionUserId',checkSessionId());
$SMT->bindParam (':contactId',$contactId);
$SMT->bindParam (':offset',$offset);
$SMT->execute();
And here is the error
Error:SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''4'' at line 6
My question is, is version 5.6.25 supporting this feature?