1
votes

I have a question regarding prepared statements using PDO.I have a query which selects all records from a table without any bind value i.e there are no filters.It is as simple as "SELECT * FROM EMP".The query would be exceuted a number of times as records are displayed using pagination.Is there any benefit using prepared sql statement or should I just stick to simple query statement?

Thanks for the help. Simmy

1
this answer will shed some light about the performance point of view: stackoverflow.com/a/671802/1291428 - Sebas
@Sebas the linked article is almost a decade old - Your Common Sense
@YourCommonSense oh you're right he's talking about mysql 4.1 ... I'm going to see If I can find something else - Sebas
So, here we go: webdevrefinery.com/forums/topic/… He's not talking about the cache though, it would deserve some delving. - Sebas

1 Answers

3
votes

Selecting all the records for pagination is an oxymoron.

If you are using pagination, it means you are selecting only certain page, a subset of records.
Selecting ALL records to display only part of them makes no sense. You have to select only records you are going yo show, using LIMIT operator.

And yes, you have to use prepared statements for LIMIT clause parameters in this case. Though there is some pitfall, explained here