2017 © Pedro Peláez
 

package database

Simple database driver for mysql (PDO)

image

hadi/database

Simple database driver for mysql (PDO)

  • Sunday, September 10, 2017
  • by im4aLL
  • Repository
  • 1 Watchers
  • 18 Stars
  • 34 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 7 Forks
  • 0 Open issues
  • 3 Versions
  • 6 % Grown

The README.md

Updated version can be found here https://github.com/im4aLL/roolith-database, (*1)

PDO MySql driver class for PHP

Introduction

This is simple class for SELECT, INSERT, UPDATE, DELETE query for MySQL, (*2)

Installation

composer require hadi/database, (*3)

if you don't want composer then simple grab class file from src/Database.php and use it!, (*4)

Usage

Connection

$config = [
    'host' => 'localhost',
    'name' => 'temp',
    'username' => 'root',
    'password' => '',
];

$db = new \Hadi\Database();
$db->connect($config);

Disconnect

$db->disconnect();

Select Query

Method #1

$db->query('SELECT * FROM users')->get();
$db->query('SELECT * FROM users')->first();

Method #2

$db->table('users')->select([
    'field' => ['name', 'username'],
])->first();
$db->table('users')->select([
    'field' => ['name', 'username'],
    'condition' => 'WHERE id > 0',
    'limit' => '0, 10',
    'orderby' => 'name',
    'groupby' => 'name',
])->first();

Insert

Insert data:, (*5)

$db->table('users')->insert(['name' => 'John doe', 'email' => 'john@email.com']);

Insert data when supplied email john@email.com not exists in table users:, (*6)

$db->table('users')->insert(
    ['name' => 'John doe', 'email' => 'john@email.com'],
    ['email']
);
result
affected_row
inserted_id
is_duplicate

Update

Update data where id = 1, (*7)

$db->table('users')->update(
    ['name' => 'John doe', 'email' => 'john@email.com'],
    ['id' => 1]
);

or, (*8)

$db->table('users')->update(
    ['username' => 'johndoe'],
    'id = 1'
);

update username if nobody else using same username, (*9)

$db->table('users')->update(
    ['username' => 'johndoe'],
    ['id' => 4],
    ['username']
);
result
affected_row
is_duplicate

Delete

$db->table('users')->delete(['id' => 4]);
result
affected_row

The Versions

10/09 2017

dev-master

9999999-dev

Simple database driver for mysql (PDO)

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Habib Hadi

10/09 2017

1.0.1

1.0.1.0

Simple database driver for mysql (PDO)

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Habib Hadi

10/09 2017

1.0.0

1.0.0.0

Simple database driver for mysql (PDO)

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Habib Hadi