|
PDOStatement::rowCountReturns the number of rows affected by the last SQL statement Description
public int PDOStatement::rowCount()
PDOStatement::rowCount returns the number of
rows affected by the last DELETE, INSERT, or UPDATE statement
executed by the corresponding
For statements that produce result sets, such as
ParametersThis function has no parameters. Return ValuesReturns the number of rows. Errors/Exceptions
Emits an error with level
Throws a PDOException if the attribute Examples
Example #1 Return the number of deleted rows PDOStatement::rowCount returns the number of rows affected by a DELETE, INSERT, or UPDATE statement.
The above example will output something similar to: Return number of rows that were deleted: Deleted 9 rows. Example #2 Counting rows returned by a SELECT statement 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 matching rows.
The above example will output something similar to: There are 2 matching records. See Also
|