So in the end I must use two select.
First to count the number of all rows:
$res = $conn->query("SELECT COUNT(*) FROM table1"); // get the count
$total_recs = $res->fetch_row()[0]; // read the first column of the returned row
Second to paginate like:
$res = $conn->query("SELECT name,prename FROM table1 LIMIT 1,5"); // first 5 rows
$res->execute();
$res->fetchAll(PDO::FETCH_OBJ);
I wonder if it's possible to combine this two SELECT statements into one.
Because using two select I must interact with my table twice, witch is a big table. Maybe combine this into one SELECT may reduce the time to query.