Skip to content

rowCount() is not working anyway #664

@tgely

Description

@tgely

return $Q->rowCount();

rowCount() is not working anyways in updates and delete. DB::Save when update used not pass driver options so would be better to use DB::prepare instead.

PHP doc refered this issue: https://www.php.net/manual/en/pdostatement.rowcount.php#104930

I suggest to use directly driver_options for prepare functions only:

      if (!isset($driver_options[\PDO::MYSQL_ATTR_FOUND_ROWS]) || $driver_options[\PDO::MYSQL_ATTR_FOUND_ROWS] === FALSE) {
            $driver_options[\PDO::MYSQL_ATTR_FOUND_ROWS] = TRUE;
        }

or prepare directly

$Qsave = $this->app->db->prepare('update :table_orders set billing_country = :country_name where orders_id = :orders_id', [
 '\PDO::MYSQL_ATTR_FOUND_ROWS' => TRUE
]);
$Qsave->bind...
...
$Qsave->execute();
$affected = $Qsave->rowCount();

DB::save and DB::delete are not safety in all enviroments and the documentations is false.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions