2017 © Pedro Peláez
 

library pdomodel

Simple PDO-based Model

image

phpset/pdomodel

Simple PDO-based Model

  • Friday, July 13, 2018
  • by andreinwald
  • Repository
  • 2 Watchers
  • 0 Stars
  • 122 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 4 Versions
  • 42 % Grown

The README.md

PdoModel - helper methods for MySql and Query Builder with raw PDO speed

Example of using:, (*1)

class YoutubeVideosModel extends \PdoModel\PdoModel
{
    const TABLE = 'youtube_videos';

    protected function create($title, $src) {
        $this->insert(['title' => $title, 'src' => $src]);
    }
}
$youtubeVideosModel = new YoutubeVideosModel(new \Pdo());

$result = $youtubeVideosModel->select(['id', 'likes', 'url'])
    ->whereEqual('published', 1)
    ->where('likes', '>', 100)
    ->orderBy('likes desc')
    ->limit(100)
    ->offset(2000)
    ->groupBy('author')
    ->getAllRows();
var_dump($result);

Setup

composer require phpset/pdomodel

Check that you have proper PHP extentions, (*2)

# Change 8.2 below to your current PHP version
sudo apt install php8.2-pdo php8.2-pdo-mysql php8.2-pdo-sqlite

You need to create a usual PDO connection:, (*3)

$connection = new \PDO(
    "mysql:host=127.0.0.1;dbname=YOURDBNAME;charset=utf8mb4",
    "YOURUSER",
    "YOURPASSWORD",
    [
            \PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC,
            \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
    ]
);

Example for creating PDO in Symfony service config:, (*4)

PDO:
  class: \PDO
  arguments:
    - "mysql:host=127.0.0.1;dbname=YOURDBNAME;charset=utf8mb4"
    - "YOURUSER"
    - "YOURPASSWORD"
    -
      !php/const PDO::ATTR_DEFAULT_FETCH_MODE: !php/const PDO::FETCH_ASSOC
      !php/const PDO::ATTR_ERRMODE: !php/const PDO::ERRMODE_EXCEPTION

SQLite example, (*5)

$connection = new \PDO('sqlite::db.sqlite');
new PdoModel($connection)->setTable('test_table');

Tests

# run tests
./vendor/bin/phpunit

# Check coverage
php -dxdebug.mode=coverage ./vendor/bin/phpunit --coverage-text

Inspired by

The Versions

13/07 2018

dev-master

9999999-dev

Simple PDO-based Model

  Sources   Download

The Requires

  • ext-pdo *

 

20/03 2018

v0.1.2

0.1.2.0

Simple PDO-based Model

  Sources   Download

The Requires

  • ext-pdo *

 

01/03 2018

v0.1.1

0.1.1.0

Simple PDO-based Model

  Sources   Download

The Requires

  • ext-pdo *

 

06/02 2018

v0.1

0.1.0.0

Simple PDO-based Model

  Sources   Download

The Requires

  • ext-pdo *