SQLite via PDO - Find affected rows

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
Stryks
Forum Regular
Posts: 746
Joined: Wed Jan 14, 2004 5:06 pm

SQLite via PDO - Find affected rows

Post by Stryks »

Has anyone else come across SQLite not showing affected rows when using the prepare() / execute() method?

Code: Select all

$test = $link->prepare('DELETE FROM tbl_admin_postcodes');  // $link is a valid connection
$test->execute();

 echo "Affected rows: " . $test->rowCount(); // returns 0 though rows are removed
It returns a valid PDOStatement, and I can pull data on selects and so forth, however INSERTs and DELETEs all return 0 if I call rowCount().

Anyone worked with PDO SQLite before? Ever found this?

Cheers
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

It's not you; PDO can be buggy in this respect, though it seems to affect only certain version of DB engines.

Adding a COUNT column can work around SELECT queries, but I have no idea how to work around DELETE or UPDATE :-(
User avatar
Stryks
Forum Regular
Posts: 746
Joined: Wed Jan 14, 2004 5:06 pm

Post by Stryks »

8O

Well ...

I'm kinda lost for words. If I want to use SQLite3 then I have to use PDO ... and PDO implementation is broken. That'd be a FANTASTIC thing to have in the PHP documentation so a person could read it BEFORE they went off and wrote a stack of code for it.

It probably doesn't matter that much, but I always like to build that into my abstraction so that I can easily check that actions have had the desired effect.

I just went back and had a tinker, and yeah ... I cant get affected rows from anything. exec() and query() expose no extra info.

Dammit.

Thanks for the reply though 8)
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

That DOES suck :-(

You should contribute a note to the man page - at least it will help the next person. Make sure you include your version and platform.
Post Reply