osCommerce / oscommerce2

osCommerce Online Merchant v2.x
http://www.oscommerce.com
MIT License
281 stars 222 forks source link

rowCount() is not working anyway #664

Open tgely opened 3 years ago

tgely commented 3 years ago

https://github.com/osCommerce/oscommerce2/blob/de0e97d15d43ac6a9a6cfb2847134a82a0148f2b/catalog/includes/OSC/OM/Db.php#L300

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.