I have been struggling with how to do a search script with prepare
statement of php, Can you please guide me?
I have tried to do this but for some reason doesn't work when use the LIMIT
function.
Below is my current script and I have these issue:
Fatal error: Uncaught exception 'PDOException' with message '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 '10' at line 4' in C:\wamp\www\training\modules\training\index7.php:36 Stack trace: #0 C:\wamp\www\training\modules\training\index7.php(36): PDOStatement->execute() #1 {main} thrown in C:\wamp\www\training\modules\training\index7.php on line 36
I have edited this question taking your sugestions but I don't know what happend.
php code:
$maxRows = 10;
$pageNum = 0;
$startRow = $pageNum * $maxRows;
$sqlq = "SELECT ent_entrenamientos.id, ent_entrenamientos.descripcion, ent_entrenamientos.duracion, ent_instructores.proveedor, CONCAT(ent_instructores.nombre_pila, ' ', ent_instructores.apellido_paterno ) AS instructor, ent_entrenamientos.vencimiento, ent_tipos.descripcion AS tipo_entrenamiento, ent_entrenamientos.nivel_alerta FROM ent_entrenamientos
LEFT JOIN ent_instructores ON ent_entrenamientos.ent_instructor_id = ent_instructores.id
LEFT JOIN ent_tipos ON ent_entrenamientos.ent_tipo_id = ent_tipos.id
WHERE ent_entrenamientos.borrado_logico = FALSE AND ent_entrenamientos.descripcion LIKE :descripcion LIMIT :startow :maxrows ";
$stmtq = $DB_con->prepare($sqlq);
$stmtq->bindValue(':descripcion', "%$descripcion%", \PDO::PARAM_STR);
$stmtq->bindValue(':startrow', $startRow, \PDO::PARAM_INT);
$stmtq->bindValue(':maxrows', $maxRows, \PDO::PARAM_INT);
$stmtq->execute();
I apreaciate your help in advance