Problem on Database class |
|||
|---|---|---|---|
| Date: | 08/27/2008 | Severity: | Major |
| Status: | Bogus | Reporter: | bit_01 |
| Version: | 1.6.3 | ||
| Keywords: | Libraries, Database Class | ||
Description
When I use the database class (MySQL) I can’t know the numbers of rows affected on INSERT, UPDATE or DELETE operations.
The reason is that the database class have not any method to return this value.
The num_rows() method use the PHP function mysql_num_rows that returns the rows on a SELECT.
INSERT, UPDATE or DELETE needs to use the mysql_affected_rows().
I suggest to create a method named affected_rows() that use mysql_affected_rows() function.
Code Sample
$sql = 'DELETE FROM `cod` WHERE `id` = 1 LIMIT 1';
$result = $this->db->query($sql);
$total = $result->num_rows();
if ( $total > 0 ) {
die( 'It was deleted'. );
} else {
die( 'It was not deleted'. );
}
Expected Result
It was deleted.
I expect to have a way of know how many rows had been affected on INSERT, UPDATE or DELETE operations.
Actual Result
Fatal error: Call to a member function num_rows() on a non-object in D:\xampp\htdocs\super\sys\app\controllers\adm\c.php on line 172
Comment on Bug Report
| Posted by: Derek Jones on 27 August 2008 4:26pm | |
|
|
That method already exists… $this->db->affected_rows() |
| Posted by: bit_01 on 27 August 2008 5:06pm | |
|
|
I preferred something like $result->affected_rows() similar to $result->num_rows() $sql = ‘DELETE FROM `cod` WHERE `id` = 1 LIMIT 1’; But, You are right. Please, if you can, remove this bug report or declared it resolved. Thanks a lot. |
