What are the potential pitfalls of creating a custom database class in PHP instead of using built-in classes like mysqli or PDO?

One potential pitfall of creating a custom database class in PHP instead of using built-in classes like mysqli or PDO is the risk of reinventing the wheel and introducing bugs or security vulnerabilities. Using built-in classes ensures better compatibility, performance, and security as they are maintained and updated by the PHP community.

// Using built-in PDO class to establish a database connection
$dsn = 'mysql:host=localhost;dbname=mydatabase';
$username = 'username';
$password = 'password';

try {
    $db = new PDO($dsn, $username, $password);
    $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
    echo 'Connection failed: ' . $e->getMessage();
}