2017 © Pedro PelĂĄez
 

library simple-pdo-wrapper

As its name suggests, it is a simple PDO wrapper to facilitate/simplify/beautify sql syntax and PDO usage.

image

adrian0350/simple-pdo-wrapper

As its name suggests, it is a simple PDO wrapper to facilitate/simplify/beautify sql syntax and PDO usage.

  • Thursday, October 19, 2017
  • by adrian0350
  • Repository
  • 1 Watchers
  • 2 Stars
  • 11 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 12 Versions
  • 0 % Grown

The README.md

Introduction

SimplePDOWrapper's purpose is to help you handle simple database actions with a reduced amount of code as well as writting less-messy code following a simple structure., (*1)

You can: * Save * Update * Delete (with conditions) * Delete all (without conditions) * Find one * Find all * Set database (switch on the fly) * Error handling through public var @errors, (*2)

Dependencies

PHP Version

This class is compatible with PHP 5.0 and above due to the PHP PDO dependency., (*3)

Installing

Add this library to your Composer configuration. In composer.json:, (*4)

  "require": {
    "adrian0350/simple-pdo-wrapper": "1.*"
  }

Or

If you're using bash., (*5)

$ composer require adrian0350/simple-pdo-wrapper

Usage

For usage just call the methods from your SimplePDOWrapper instance object., (*6)

<?php

require_once dirname(dirname(__FILE__)).'/src/SimplePDOWrapper.php';

$conf = array(
    'database' => 'your_db_name',
    'username' => 'root',
    'password' => 'toor',
    'host' => 'localhost'
);
$SimplePDOWrapper = new SimplePDOWrapper($conf);

Options param

Options are available with * conditions * > * < * >= * <= * != * LIKE * And more complex clauses: (UNIX_TIMESTAMP(calldate) + callduration) >= * limit * fields * order, (*7)

// For now conditions only has basic clause.
$options = array(
    'conditions' => array(
            'username' => 'john.doe@email.com'
        ),
    'limit' => 10,
    'fields' => array('id', 'username', 'password', 'name'),
    'order' => array('id DESC')
);

Save New Entry

// After saving you will receive the last saved entity.
$save = array(
    'id' => 10,
    'username' => 'jaime.ziga@gmail.com',
    'password' => 'Dude, it\'s private
',
    'name' => 'John Doe'
);
$user_saved = $SimplePDOWrapper->save('users', $save);

Update New Entry

// When updating it will only return true or false.
$update = array(
    'name' => 'AdriĂĄn ZĂșñiga'
);
$SimplePDOWrapper->update('users', $update, array(
    'conditions' => array(
        'id' => $user_saved['id']
    )
));

findOne & findAll

This methods receive 3 params in total, entity (table), options (see above) and assoc (boolean) to get an associative array or STDClass object., (*8)

// This findOne will return the one entity array or empty array.
$user = $SimplePDOWrapper->findOne('users', $options, $assoc = true);

// And findAll will return empty array or an array of STDClass objects.
$users = $SimplePDOWrapper->findAll('users', $options, $assoc = false);

delete & deleteAll

The only difference between delete and deleteAll is that 'delete' receives the options argument with 'conditions'., (*9)

// Options just needs compliant conditions.
$options = array(
    'conditions' => array(
        'id' => 666
    )
);

// Boolean
$deleted = $this->SimplePDOWrapper->delete('users', $options);

// Boolean
$deleted = $this->SimplePDOWrapper->deleteAll('users');

Switch database

Just like instantiating the class., (*10)

// Switch database with setDatabase() method
// and pass credentials in $conf array.
$conf = array(
    'database' => 'another_db',
    'username' => 'root',
    'password' => 'toor',
    'host' => 'localhost'
);

// Will return boolean.
$SimplePDOWrapper->setDatabase($conf);
``````

## Handling errors
Since it's internally set to handle errors you can handle them like this.

// As I mentioned before update method will return a boolean value. $updated = $SimplePDOWrapper->update('users', $update, array( 'conditions' => array( 'id' => $user_saved['id'] ) )), (*11)

// Watching errors if (!$updated || $SimplePDOWrapper->errors) { var_dump($SimplePDOWrapper->errors['code']); var_dump($SimplePDOWrapper->errors['message']); } ```, (*12)

The Versions

19/10 2017

dev-master

9999999-dev https://github.com/Adrian0350/SimplePDOWrapper

As its name suggests, it is a simple PDO wrapper to facilitate/simplify/beautify sql syntax and PDO usage.

  Sources   Download

MIT

The Requires

  • php >=5.0

 

by Jaime ZĂșñiga

database php wrapper pdo mysql

19/10 2017

1.3.0

1.3.0.0 https://github.com/Adrian0350/SimplePDOWrapper

As its name suggests, it is a simple PDO wrapper to facilitate/simplify/beautify sql syntax and PDO usage.

  Sources   Download

MIT

The Requires

  • php >=5.0

 

by Jaime ZĂșñiga

database php wrapper pdo mysql

22/09 2017

1.2.1

1.2.1.0 https://github.com/Adrian0350/SimplePDOWrapper

As its name suggests, it is a simple PDO wrapper to facilitate/simplify/beautify sql syntax and PDO usage.

  Sources   Download

MIT

The Requires

  • php >=5.0

 

by Jaime ZĂșñiga

database php wrapper pdo mysql

21/09 2017

1.2.0

1.2.0.0 https://github.com/Adrian0350/SimplePDOWrapper

As its name suggests, it is a simple PDO wrapper to facilitate/simplify/beautify sql syntax and PDO usage.

  Sources   Download

MIT

The Requires

  • php >=5.0

 

by Jaime ZĂșñiga

database php wrapper pdo mysql

19/09 2017

1.0.7

1.0.7.0 https://github.com/Adrian0350/SimplePDOWrapper

As its name suggests, it is a simple PDO wrapper to facilitate/simplify/beautify sql syntax and PDO usage.

  Sources   Download

MIT

The Requires

  • php >=5.0

 

by Jaime ZĂșñiga

database php wrapper pdo mysql

17/09 2017

1.0.6

1.0.6.0 https://github.com/Adrian0350/SimplePDOWrapper

As its name suggests, it is a simple PDO wrapper to facilitate/simplify/beautify sql syntax and PDO usage.

  Sources   Download

MIT

The Requires

  • php >=5.0

 

by Jaime ZĂșñiga

database php wrapper pdo mysql

16/09 2017

1.0.5

1.0.5.0 https://github.com/Adrian0350/SimplePDOWrapper

As its name suggests, it is a simple PDO wrapper to facilitate/simplify/beautify sql syntax and PDO usage.

  Sources   Download

MIT

The Requires

  • php >=5.0

 

by Jaime ZĂșñiga

database php wrapper pdo mysql

16/09 2017

1.0.4

1.0.4.0 https://github.com/Adrian0350/SimplePDOWrapper

As its name suggests, it is a simple PDO wrapper to facilitate/simplify/beautify sql syntax and PDO usage.

  Sources   Download

MIT

The Requires

  • php >=5.0

 

by Jaime ZĂșñiga

database php wrapper pdo mysql

16/09 2017

1.0.3

1.0.3.0 https://github.com/Adrian0350/SimplePDOWrapper

As its name suggests, it is a simple PDO wrapper to facilitate/simplify/beautify sql syntax and PDO usage.

  Sources   Download

MIT

The Requires

  • php >=5.0

 

by Jaime ZĂșñiga

database php wrapper pdo mysql

16/09 2017

1.0.2

1.0.2.0 https://github.com/Adrian0350/SimplePDOWrapper

As its name suggests, it is a simple PDO wrapper to facilitate/simplify/beautify sql syntax and PDO usage.

  Sources   Download

MIT

The Requires

  • php >=5.0

 

by Jaime ZĂșñiga

database php wrapper pdo mysql

16/09 2017

1.0.1

1.0.1.0 https://github.com/Adrian0350/SimplePDOWrapper

As its name suggests, it is a simple PDO wrapper to facilitate/simplify/beautify sql syntax and PDO usage.

  Sources   Download

MIT

The Requires

  • php >=5.0

 

by Jaime ZĂșñiga

database php wrapper pdo mysql

16/09 2017

1.0

1.0.0.0 https://github.com/Adrian0350/SimplePDOWrapper

As its name suggests, it is a simple PDO wrapper to facilitate/simplify/beautify sql syntax and PDO usage.

  Sources   Download

MIT

The Requires

  • php >=5.0

 

by Jaime ZĂșñiga

database php wrapper pdo mysql