pdo and limit clause

01.04.2008

i don't know(and don't care) who wrote this pdo library but it's a joke. there are some ridiculous things in library's functions like pdo::rowcount(). if you look at php manual you'll see
For most databases, PDOStatement->rowCount() does not return the number of rows affected by a SELECT statement. Instead, use PDO->query() to issue a SELECT COUNT(*) statement with the same predicates as your intended SELECT statement, then use PDOStatement->fetchColumn() to retrieve the number of rows that will be returned. Your application can then perform the correct action.
for the god's sake, what are those "most databases". mysql?, postgresql?, ms sql?. wasting of overhead is too ridiculous. the only sensible solution is count($row) i guess.

another thing is when you use parameters in limit clause, you get sql syntax error(errno. 1064 for mysql), even if your sql statement is valid. you can also perfectly query without parameters. the problem only occurs when parameters are used. there are some bug reports(here's one: http://bugs.php.net/bug.php?id=40740). pdo::execute() cause this problem 'cos it parses limit parameters as strings which is not allowed in mysql. you need to bind parameters with pdo::bindparam() to parse 'em as integers. the funny thing is some bug reports are way back to 2005.
blog comments powered by Disqus