Install via Composer

The recommended way to add PDOdb to your project.

Requirements

  • PHP 8.0 or higher
  • The PDO extension enabled (enabled by default in most environments)
  • The pdo_mysql driver enabled
  • MySQL 5.7+ or MariaDB 10.3+

Install

Run this command in your project root:

composer require decmuc/pdodb

That's it. Composer handles the autoloading – no additional setup needed.

Usage

Include Composer's autoloader and import the class:

require 'vendor/autoload.php';

use decMuc\PDOdb\PDOdb;

Create a connection and run your first query:

$db = new PDOdb([
    'host'     => 'localhost',
    'username' => 'root',
    'password' => 'secret',
    'db'       => 'my_database',
    'charset'  => 'utf8mb4',
]);

$users = $db->get('users');
// SELECT * FROM users

$user = $db->whereInt('id', 1)->getOne('users');
// SELECT * FROM users WHERE id = 1 LIMIT 1

Development version

To install the latest unreleased version directly from the main branch:

composer require decmuc/pdodb:dev-main
The development version may contain untested features. Do not use in production.

Links