Base Directory:
/home/ecedu/public_html/cce/Models
db = DB::instance()->getConnection();
}
public function getImageByType(int $typeId): ?array
{
$sql = "SELECT * FROM dbs_image WHERE type_id = :t";
$stmt = $this->db->prepare($sql);
$stmt->bindValue(':t', $typeId, PDO::PARAM_INT);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
return $row ?: null;
}
public function updateImageRecord(int $imgId, string $ext, int $userId): bool
{
$sql = "UPDATE dbs_image SET img_ext = :ext, user_id = :u WHERE img_id = :id";
$stmt = $this->db->prepare($sql);
$stmt->bindValue(':ext', $ext);
$stmt->bindValue(':u', $userId, PDO::PARAM_INT);
$stmt->bindValue(':id', $imgId, PDO::PARAM_INT);
return $stmt->execute();
}
public function insertImageRecord(int $typeId, string $ext, int $userId): int
{
$sql = "INSERT INTO dbs_image (type_id, img_ext, user_id) VALUES (:t, :e, :u)";
$stmt = $this->db->prepare($sql);
$stmt->bindValue(':t', $typeId, PDO::PARAM_INT);
$stmt->bindValue(':e', $ext);
$stmt->bindValue(':u', $userId, PDO::PARAM_INT);
if (!$stmt->execute()) {
return 0;
}
return (int)$this->db->lastInsertId();
}
public function getAdsByType(int $typeId): ?array
{
$sql = "SELECT * FROM dbs_ads WHERE type_id = :t";
$stmt = $this->db->prepare($sql);
$stmt->bindValue(':t', $typeId, PDO::PARAM_INT);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
return $row ?: null;
}
public function updateAdsRecord(int $imgId, string $url, string $ext, int $userId): bool
{
$sql = "UPDATE dbs_ads SET img_url = :url, img_ext = :ext, user_id = :u WHERE img_id = :id";
$stmt = $this->db->prepare($sql);
$stmt->bindValue(':url', $url);
$stmt->bindValue(':ext', $ext);
$stmt->bindValue(':u', $userId, PDO::PARAM_INT);
$stmt->bindValue(':id', $imgId, PDO::PARAM_INT);
return $stmt->execute();
}
public function insertAdsRecord(int $typeId, string $url, string $ext, int $userId): int
{
$sql = "INSERT INTO dbs_ads (type_id, img_url, img_ext, user_id) VALUES (:t, :u, :e, :u)";
$stmt = $this->db->prepare($sql);
$stmt->bindValue(':t', $typeId, PDO::PARAM_INT);
$stmt->bindValue(':u', $url);
$stmt->bindValue(':e', $ext);
$stmt->bindValue(':u', $userId, PDO::PARAM_INT);
if (!$stmt->execute()) {
return 0;
}
return (int)$this->db->lastInsertId();
}
}