Once you have a query object built, either through a prepared statement or through the builder, you must then execute() the query and retrieve the results. Depending on the query type used, the results returned will vary.
echo$user['email']." needs to verify his/her account\n";
Select - as_object() and as_assoc()
When iterating over a result set, the default type will be an associative array with the column names or aliases as the keys. As an option, before calling execute(), you can specify to return the result rows as an object by using the as_object() method. Theas_object() method takes one parameter, the name of the class of your choice, but will default to TRUE which uses thestdClass. Here is the example again using stdClass.
Sometime you only want a single value from a query. The get() method returns the value of the named column from the current row. The second parameter, $default, is used to supply a default value when the result is NULL.
The mysql database driver returns a Database_Result that works with a MySQL Resource data type. Since this resource lives outside of PHP environment, it can't be serialized which means it also can't be cached. To get around this the Database_Resultobject has the cached() method that returns a Database_Result_Cached object of the result set. TheDatabase_Result_Cached can be serialized and cached, but can take up more memory.
NOTE: Currently, the PDO diver always returns a class of Database_Result_Cached, so cached() just returns itself.
The cached() function doesn't actually do any caching, it simply returns the result in a way that can be serialized and cached. You will need to use the Cache Module or some other caching method.
Select - count()
The Database_Result object implements the Countable Interface. The method count() returns the total row count in the result set.
NOTE: This is the count of the current result set, not a count of how many records are in the database. This is important to point out especially when using limit() and offset() in your query.
For a complete list of methods available when working with a result set see Database_Result.
DB::insert returns an array of two values: the last insert id and the number of affected rows.