Skip to content

ComStudio/cbase

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

60 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cbase

Build Status

CRUD library for MySQL with PDO

How to use it

Install with composer

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

Configuration

# config/bootstrap.php

<?php
	return 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 library for MySQL with PDO

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 100.0%