$my_conn = new PDO('sqlite:my_student.sqlite3');
We will use $my_conn to execute our query. <?php
// Create (connect to) SQLite database in file
$my_conn = new PDO('sqlite:my_student.sqlite3');
// Set errormode to exceptions
$my_conn->setAttribute(PDO::ATTR_ERRMODE,
PDO::ERRMODE_EXCEPTION);
////////////////////
echo "<br>LIMIT 0, 10 <br><br>";
$sql="SELECT * FROM student LIMIT 0,10";
$step = $my_conn->prepare($sql);
$step->execute();
$step = $step->fetchAll();
echo "<table>";
foreach ($step as $row) {
echo "<tr ><td>$row[id]</td><td>$row[name]</td><td>$row[class]</td></tr>";
}
echo "</table>";
?>
Output
1 John Deo Four
2 Max Ruin Three
3 Arnold Three
4 Krish Star Four
5 John Mike Four
6 Alex John Four
7 My John Rob Five
8 Asruid Five
9 Tes Qry Six
10 Big John Four
Note that the first record is at 0th position and 10 records are returned staring from 0th position record.
$val1=5;
$val2=10;
echo "<br>LIMIT 5, 10 <br><br>";
$sql="SELECT * FROM student LIMIT :val1,:val2";
$step = $my_conn->prepare($sql);
$step->bindParam(':val1', $val1,PDO::PARAM_INT,10);
$step->bindParam(':val2', $val2,PDO::PARAM_INT,10);
$step->execute();
$step = $step->fetchAll();
echo "<table>";
foreach ($step as $row) {
echo "<tr ><td>$row[id]</td><td>$row[name]</td><td>$row[class]</td></tr>";
}
echo "</table>";
Output is here LIMIT 5, 10
6 Alex John Four
7 My John Rob Five
8 Asruid Five
9 Tes Qry Six
10 Big John Four
11 Ronald Six
12 Recky Six
13 Kty Seven
14 Bigy Seven
15 Tade Row Four
Author
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.