PHP MySQL Using the LIMIT Clause
⏱️ PHP MySQL – Using the LIMIT Clause
The LIMIT clause in MySQL is used to restrict the number of records returned in a SELECT query. It’s very useful for pagination or displaying a subset of data.
1️⃣ Using mysqli (Procedural)
✅ Returns first 3 rows from the table.
2️⃣ Using mysqli Object-Oriented
✅ LIMIT offset, count → skip offset rows and return count rows.
3️⃣ Using PDO
✅ In PDO, bind parameters as PDO::PARAM_INT when using LIMIT.
4️⃣ Key Points
-
LIMIT restricts the number of rows returned.
-
Syntax:
-
LIMIT count→ returns the firstcountrows -
LIMIT offset, count→ skipoffsetrows, returncountrows
-
-
Useful for pagination, e.g., showing 10 records per page.
-
Works with mysqli procedural, object-oriented, and PDO.
-
Always bind LIMIT parameters as integers in PDO to avoid errors.
