Examples for presentation.

This commit is contained in:
giedrius
2024-11-19 13:57:03 +02:00
commit 41f2b5eec1
23 changed files with 3351 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
<?php
namespace Example\VeryGood;
use PDO;
class Repository
{
private PDO $pdo;
public function __construct(PDO $pdo)
{
$this->pdo = $pdo;
}
/**
* @return Product[]
*/
public function getProducts($skus): array
{
$quotedSkus = [];
foreach ($skus as $sku) {
$quotedSkus[] = $this->pdo->quote($sku);
}
$skusStr = implode(',', $quotedSkus);
$sql = "SELECT * FROM products where id in ($skusStr)";
return $this->pdo->query($sql)->fetchAll(PDO::FETCH_CLASS, Product::class);
}
}