1. Go to this page and download the library: Download elriseio/dbal-bundle library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
class MyService
{
public function __construct(private DbalManagerFactory $factory) {}
public function updateBulkData(array $rows): void
{
$bulkUpdater = $this->factory->createBulkUpdater();
$bulkUpdater->update('my_table', $rows);
}
}
/** @var BulkInserterInterface $inserter */
$inserter->insert('user_table', [
[
'id' => IdStrategy::AUTO_INCREMENT, // The ID will be generated by the database.
'email' => ['[email protected]', ParameterType::STRING],
'created_at' => (new \DateTime())->format('Y-m-d H:i:s'),
],
[
'id' => IdStrategy::UUID, // The ID will be generated in the code.
'email' => ['[email protected]', ParameterType::STRING],
'created_at' => (new \DateTime())->format('Y-m-d H:i:s'),
],
[
// The ID will be generated in the code.
'email' => ['[email protected]', ParameterType::STRING],
'created_at' => (new \DateTime())->format('Y-m-d H:i:s'),
],
]);
$ids = $bulkUpserter->upsertManyReturningIds(
'api_history',
[
['id' => IdStrategy::AUTO_INCREMENT, 'status' => 'success', 'updated_at' => date('Y-m-d H:i:s')],
['id' => IdStrategy::AUTO_INCREMENT, 'status' => 'pending', 'updated_at' => date('Y-m-d H:i:s')],
],
['status', 'updated_at'],
);
// $ids is [123, 124] in the order of the input rows.
// Get a single row by SQL (LIMIT 1 is automatically added).
$result = $finder->fetchOneBySql(
'SELECT * FROM api_history WHERE id = :id',
['id' => $id],
ApiDto::class
);
// Get multiple rows with mapping to DTO.
$results = $finder->fetchAllBySql(
'SELECT * FROM api_history ORDER BY id LIMIT 10',
[],
ApiDto::class
);
// Find a record by ID.
$result = $finder->findById($id, 'api_history', ApiDto::class);
// Find records by ID.
$result = $finder->findByIdList($idList, 'api_history', ApiDto::class);