PDOStatement::rowCount() can be used to get the number of rows affected by the last INSERT
, UPDATE
, or DELETE
.
Does it have the overhead of issuing a second request, such as MySQL's ROW_COUNT(), or is the number of affected rows part of the metadata it receives when executing the statement itself, and as such is "free" resource-wise?
I've enabled the mysql log with:
SET GLOBAL general_log = 'ON';
And then ran an insert query with prepared statement followed by a rowCount
call. The log shows this:
32 Prepare INSERT INTO test VALUES(?, ?, ?)
32 Execute INSERT INTO test VALUES(NULL, '11', '22')
32 Close stmt
So there is no extra call.