Bastiaan van der Plaat

A nice site filled with rubbish

PHP Database Class

This is a simple PHP PDO static class, it's easy to use.

<?php

// Made by Bastiaan van der Plaat (https://bastiaan.plaatsoft.nl/)

class Database {
    protected static $pdo, $queryCount = 0;

    public static function connect ($type, $host, $user, $password, $dbname) {
        static::$pdo = new PDO($type . ':host=' . $host . ';dbname=' . $dbname, $user, $password, [
            PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
            PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ
        ]);
    }

    public static function queryCount () {
        return static::$queryCount;
    }

    public static function query ($query, $parameters = []) {
        static::$queryCount++;
        $statement = static::$pdo->prepare($query);
        $statement->execute($parameters);
        return $statement;
    }
}

First you need to connect then you can run queries and get the queryCount.