我需要在查询中传递OFFSET的动态变量。我搜索并发现自Mysql 5.6以来,这是支持的。我使用的是5.6.25版,但我仍然遇到语法错误。
这是我的代码。
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();
这是错误
错误:SQLSTATE [42000]:语法错误或访问冲突:1064 SQL语法中有错误;检查与您的MySQL服务器版本相对应的手册,以便在#4;' 4'''''''''在第6行
我的问题是,版本5.6.25是否支持此功能?