2017 © Pedro Peláez
 

framework phpdo-database

A lightweight PHP PDO database wrapper class.

image

turbopixel/phpdo-database

A lightweight PHP PDO database wrapper class.

  • Sunday, July 8, 2018
  • by turbopixel
  • Repository
  • 0 Watchers
  • 0 Stars
  • 12 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 71 % Grown

The README.md

PHPDO

GitHub code size in bytes MIT license GitHub contributors GitHub last commit packagist, (*1)

A lightweight PHP PDO database singleton wrapper class., (*2)

Docs and examples: github.com/turbopixel/PHPDO-Database, (*3)

Requirements

  • PHP 7.2+
  • MySQL/MariaDB

Install via composer

composer require turbopixel/phpdo-database

Example

PHPDO::connect("database-server.com", "database_name", "user_name", "myPassword123");

PHPDO::get()->query("SELECT stars FROM github")->fetchAll();

class PHPDO

Create database connection

\PHPDO\PHPDO::connect("database-server.com", "database_name", "user_name", "myPassword123");

An existing PDO object can be set instead, (*4)

// $pdoObject = new PDO();

PHPDO::setPdo($pdoObject);

After this, you can use the PHPDO class from everywhere., (*5)

Get instance

\PHPDO\PHPDO::get() returns the PHPDO instance, (*6)

\PHPDO\PHPDO::get()

Example: Select rows, (*7)

\PHPDO\PHPDO::get()->query("SELECT * FROM github")->fetchAll();

Get PDO instance, (*8)

\PHPDO\PHPDO::get()->getPdo()

Run MySQL query

query, (*9)

\PHPDO\PHPDO::get()->query("SELECT id FROM user WHERE active = 1");
print_r( $pdoStmnt->fetch() );

execute, (*10)

\PHPDO\PHPDO::get()->execute("UPDATE user SET active = 0 WHERE mail IS NULL");

Prepared Statement, (*11)

\PHPDO\PHPDO::get()->prepare("UPDATE github SET stars = stars+1 WHERE id = :id", ["id" => 1234]);

Helper

fetch() - Select a single row

\PHPDO\PHPDO::get()->fetch("SELECT id FROM github WHERE id = :repo", ["repo" => 553]);

\PHPDO\PHPDO::get()->fetch() is a helper method and replace this:, (*12)

$rows  = [];
$stmnt = \PHPDO\PHPDO::get()->prepare("SELECT * FROM github WHERE id = ?", [
  1234
]);

if($stmnt instanceof PDOStatement){
  $rows = $stmnt->fetchAll();
}else{
 die("QUERY ERROR");
}

print_r($rows);

fetchAll() - Select multiple rows

\PHPDO\PHPDO::get()->fetchAll("SELECT id FROM github WHERE id = :repo", ["repo" => 553]);

rowCount() - Count rows

\PHPDO\PHPDO::get()->rowCount("SELECT id FROM github WHERE id = :repo", ["repo" => 553]);

isTable() - Check table exists (MySQL only)

\PHPDO\PHPDO::get()->isTable("user_settings")

findPrimaryIndexColumn() - Find table index column (MySQL only)

\PHPDO\PHPDO::get()->findPrimaryIndexColumn("tablename", "databasename")

Internal class logging

All SQL Queries stored in PHPDO::$logs (array). Attribute \PHPDO\PHPDO::$logging must be true, (*13)

Enable logging, (*14)

\PHPDO\PHPDO::$logging = true;

Get internal query logs
Get query logs., (*15)

\PHPDO\PHPDO::get()->getLog(); // returns an array

The Versions

08/07 2018

dev-master

9999999-dev http://phpdo.hemk.es/

A lightweight PHP PDO database wrapper class.

  Sources   Download

MIT

The Requires

  • php >=7.0
  • ext-pdo *

 

database php lightweight wrapper pdo mysql

08/07 2018

1.1.2

1.1.2.0 http://phpdo.hemk.es/

A lightweight PHP PDO database wrapper class.

  Sources   Download

MIT

The Requires

  • php >=7.0
  • ext-pdo *

 

database php lightweight wrapper pdo mysql

26/04 2018

1.1.0

1.1.0.0 http://phpdo.hemk.es/

A lightweight PHP PDO database wrapper class.

  Sources   Download

MIT

The Requires

  • php >=7.0
  • ext-pdo *

 

database php lightweight wrapper pdo mysql

16/04 2018

1.0.20

1.0.20.0 http://phpdo.hemk.es/

A lightweight PHP PDO database wrapper class.

  Sources   Download

MIT

The Requires

  • php >=7.0
  • ext-pdo *

 

database php lightweight wrapper pdo mysql

16/04 2018

1.0.5

1.0.5.0 http://phpdo.hemk.es/

A lightweight PHP PDO database wrapper class.

  Sources   Download

MIT

The Requires

  • php >=7.0
  • ext-pdo *

 

database php lightweight wrapper pdo mysql