2017 © Pedro Peláez
 

library class_db

Class DB allows you to write secure SQL queries easily and work with many different databases using the same syntax.

image

samuelfaj/class_db

Class DB allows you to write secure SQL queries easily and work with many different databases using the same syntax.

  • Wednesday, July 11, 2018
  • by samuelfaj
  • Repository
  • 1 Watchers
  • 0 Stars
  • 6 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

Class_DB

, (*1)

MIT license built with PHP MySQL Ready MySQLI Ready mssql Ready sqlserv Ready pgsql Ready, (*2)

Write less. Do a lot more. Class_DB allows you to write secure SQL queris easily and work with many different databases using the same syntax, (*3)

Everytime i was working with or starting a new system, i had to look at the database documentation and choose between create a class for it using mine functions or write the system following his own. But what if the driver changed? Yeah, Everyone who is here for a while saw some changes in PHP drivers. Those changes were a painful work for great systems and even more for small teams. We saw mssql become sqlserv, mysql become mysqli and it's common to see groups deciding to change the database in the middle of the project., (*4)

Thinking about it i developed class_db. It helps us to write less SQL and don't care for the chosen database. Just write your code and class_db will do the rest. If the driver or the team resolves to change, just update it!, (*5)

Install

It's simple, just download and require it., (*6)

composer require samuelfaj/class_db

Examples

Initializing, (*7)

<?php
    require_once 'vendor/autoload.php';

    $db = new ClassDb\Db(array(
        'host'     => 'localhost'      ,  // string - Host of Connection.
        'user'     => 'username'       ,  // string - Database's User.
        'password' => 'mysecretpass'   ,  // string - User's Password.
        'database' => 'myapplication'  ,  // string - Default Database name.
        'db_type'  => 'mysql'          ,  // string - Type of Database. (It can be: 'mysql', 'mysqli' , 'mssql' , 'sqlserv' , 'pgsql').
    ));

    $sql = new ClassDb\Query($db);

Doing a simple query passing it as text:, (*8)

<?php
    require_once 'vendor/autoload.php';

    $db = new ClassDb\Db(array(
        'host'     => 'localhost'      ,  // string - Host of Connection.
        'user'     => 'username'       ,  // string - Database's User.
        'password' => 'mysecretpass'   ,  // string - User's Password.
        'database' => 'myapplication'  ,  // string - Default Database name.
        'db_type'  => 'mysql'          ,  // string - Type of Database. (It can be: 'mysql', 'mysqli' , 'mssql' , 'sqlserv' , 'pgsql').
    ));

    $sql = new ClassDb\Query($db);
    $sql->exec("SELECT * FROM users");
    var_dump($sql->query);

Doing a select without write one single character of SQL:, (*9)

<?php
    require_once 'vendor/autoload.php';

    $sql = new ClassDb\Query(array(
        'host'     => 'localhost'      ,  // string - Host of Connection.
        'user'     => 'username'       ,  // string - Database's User.
        'password' => 'mysecretpass'   ,  // string - User's Password.
        'database' => 'myapplication'  ,  // string - Default Database name.
        'db_type'  => 'mysql'          ,  // string - Type of Database. (It can be: 'mysql', 'mysqli' , 'mssql' , 'sqlserv' , 'pgsql').
    ));

    $sql->table('users');
    $sql->limit(array(0,10));

    var_dump($sql->select());

Selecting and updating a user without write one single character of SQL:, (*10)

<?php
    require_once 'vendor/autoload.php';

    $sql = new ClassDb\Query($db);
    $sql->table('users');
    $sql->where(
        array('id'    , $_POST['id']),
        array('email' , $_POST['email'])
    );
    $sql->order('id','DESC');
    $sql->limit(1);

    if( $sql->select()->have_rows ){ 
        $sql->update(array('active' => 0)); 
    }

License

This project is licensed under the MIT License - see the LICENSE file for details, (*11)

The Versions

11/07 2018

dev-v.3.0.0-dev

dev-v.3.0.0-dev

Class DB allows you to write secure SQL queries easily and work with many different databases using the same syntax.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Samuel Fajreldines

06/04 2018

dev-master

9999999-dev

Class DB allows you to write secure SQL queries easily and work with many different databases using the same syntax.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Samuel Fajreldines

06/04 2018

2.1.0

2.1.0.0

Class DB allows you to write secure SQL queries easily and work with many different databases using the same syntax.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Samuel Fajreldines

04/03 2018

1.0.0

1.0.0.0 https://github.com/samuelfaj/class_db

Class_DB allows you to write secure SQL querys easily and work with many different databases using the same syntax.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Samuel Faj

mssql mysql mysqli pgsql databases sqlserv

04/03 2018

v1.2.0

1.2.0.0 https://github.com/samuelfaj/class_db

Class_DB allows you to write secure SQL querys easily and work with many different databases using the same syntax.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Samuel Faj

mssql mysql mysqli pgsql databases sqlserv