Update Many

The updateMany method updates multiple records matching the provided filter. It performs bulk updates inside a transaction to ensure data integrity.

Purpose

The updateMany method is designed to update several records simultaneously based on a where filter. It is optimized for large-scale operations and ensures atomicity using database transactions.

Parameters

  • where — Required. Defines which records will be updated.
  • data — Required. Specifies the fields and values to update.

Return Value

Returns an associative array with:

  • status — Operation result.
  • message — Describes the update outcome.
  • affectedRows — Number of updated rows.

Returns false if no records match the filter.

Error Handling

  • Throws an exception if where or data keys are missing.
  • Throws an exception for invalid array structures.
  • Any SQL or validation error triggers a transaction rollback.

Example Usage

Updating Multiple User Records

use Lib\Prisma\Classes\Prisma;

$prisma = Prisma::getInstance();
$updatedRecords = $prisma->user->updateMany([
    'where' => ['status' => 'inactive'],
    'data'  => ['status' => 'active']
]);

echo "<pre>";
echo "Records updated: " . print_r($updatedRecords, true);
echo "</pre>";