Skip to content

CRUD (Create, Read, Update, Delete) library for MySQL with PDO

License

Notifications You must be signed in to change notification settings

devstackgroup/cbase

Repository files navigation

cbase

Build Status Coverage Status Latest Stable Version Total Downloads License

CRUD library for MySQL with PDO

By ComStudio

How to use it

Install with composer

$ composer create-project devstackgroup/cbase --stability=dev

Configuration

# config/bootstrap.php

 <?php
     return [
             'pdo' => new PDO(
                            'mysql:host=127.0.0.1;dbname=dbname',
                            'dbuser',
                            'dbpassword'
                          )
            ];
  • 127.0.0.1 - host address
  • dbname - database name
  • dbuser - database username
  • dbpassword - database password

Examples

Insert example
<?php

require 'vendor/autoload.php';

use CBase\Query\Query;

$db = new Query(require_once 'config/bootstrap.php');
$db->setTable('test');

$db->create([
    'field' => 1
   ]);
$db->close();
Read example

Read All with order by id DESC and limit 2 to assoc array

<?php

require 'vendor/autoload.php';

use CBase\Query\Query;

$db = new Query(require_once 'config/bootstrap.php');
$db->setTable('test');

$data = $db->read(['field'])
	   ->orderBy([
	    'id' => 'DESC'
	   ])
	   ->limit(2)
	   ->get([
	    'all' => true, 
	    'fetch' => 'assoc'
	   ]);
			
var_dump($data);
$db->close();

Read All to array

<?php

require 'vendor/autoload.php';

use CBase\Query\Query;

$db = new Query(require_once 'config/bootstrap.php');
$db->setTable('test');

$data = $db->read()
           ->get();
			
foreach ($data as $value) {
	var_dump($value);
}
$db->close();
Update example
<?php

require 'vendor/autoload.php';

use CBase\Query\Query;

$db = new Query(require_once 'config/bootstrap.php');
$db->setTable('test');

$db->update([
    'field' => 2
   ])
   ->where([
    'id' => 1
   ])
   ->exec();
$db->close();
Delete example
<?php

require 'vendor/autoload.php';

use CBase\Query\Query;

$db = new Query(require_once 'config/bootstrap.php');
$db->setTable('test');

$db->delete()
   ->where([
    'id' => 1
   ])
   ->exec();
$db->close();

About

CRUD (Create, Read, Update, Delete) library for MySQL with PDO

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages