In addition to methods that send queries to the database and return results, DB provides some methods that return information about a query. These methods tell you the size of the result set returned or modified by a query. DB_Result::numRows()The numRows() method returns the number of rows in a result set. This is useful for checking if any rows were selected before printing them:
The numRows() method is called on the statement handle, not on the database handle. You can only call numRows() after a SELECT query. DB_Result::numCols()The numCols() method returns the number of columns in a result set. You can use numCols() to dynamically display information about a table:
Like numRows(), the numCols() method is called on the statement handle, not on the database handle. You can only call numCols() after a SELECT query. DB::affectedRows()The affectedRows() method returns how many rows were changed by an UPDATE, INSERT, or DELETE query. It is called on the database handle, not the statement handle. This is because the query() method doesn’t return a statement handle for these kinds of queries, just a status code or error object:
blog comments powered by Disqus |