<?php
namespace inter\storage\mysql;

use Exception;
use PDO;
use PDOException;

class DB extends PDO
{
    private Config $config;
    public function __construct(Config $config)
    {
        $this->config = $config;
        try {
            // 连接数据库
            parent::__construct($this->config->GetPdoDSN(), $this->config->getUser(), $this->config->getPassword());
            // 设置错误模式为异常
            $this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        } catch (PDOException $e) {
            throw new Exception("连接数据库失败: " . $e->getMessage());
        }
    }
}
