Wallogit.com
2017 © Pedro Peláez
A PHP API to connect to different RDBMS and NoSQL
A PHP API to connect to different RDBMS and NoSQL ex. mysql, mysqli, postgresSQL, mongoDB etc.., (*1)
Under the hood, Dbcon uses PDO to connect to different supported database management system and native functions for those who have not. You would need these if you need to define multiple database connection on a single file and establish a connection later. It allows the application to connect to different database management system using a wrapper that can be used by other developer easier and cleaner, (*2)
For small projects and simple application, use native functions to connect and manage your databases.It is advisable only to use dbcon for large projects in such maintainability and productivity are tedious tasks., (*3)
Download the zip file to your computer and extract to the root directory of your server. Below is an excerpt script from example/mysql/mysql.example.php file to connect to MySQL. Example database connection scripts are located in /example folder for your reference., (*4)
'localhost',
'username'=>'root',
'password'=>'',
'port'=>'',
'dbms'=>'mysql',
'dbname'=>'your_database'
];
#class mysql
use \DBCon\MySQL\mysql as MySQL;
#setup database connection
$db=new MySQL($database['dbms'],$database['host'],$database['username'],$database['password'],$database['dbname']);
#open connection to mysql
$sth=$db->open();
#add query,bind param ,etc. to command. These will depend on your dbms
$command=$sth->query(...);
#execute command
$command->execute();
?>
br/ You may also configure your settings to shift or use different DBMS without affecting the rest of your codes. Doing so will allow applications to sync their data by reading and writing it on different databases. br/br/ Database Configuration, (*5)
'localhost',
'username'=>'root',
'password'=>'',
'port'=>'',
'dbms'=>'mysql',
'dbname'=>'your_database'
];
$database_pgsql=['host'=>'localhost',
'username'=>'postgres',
'password'=>'root',
'port'=>'5432',
'dbms'=>'pgsql',
'dbname'=>'test'
];
#class mysql ang pgsql
use \DBCon\MySQL\mysql as MySQL;
use \DBCon\pgSQL\pgsql as pgSQL;
/*setup database connection
this will remain closed unless explicitly called by '->open()' function */
$main_database=new MySQL($database_mysql['dbms'],$database_mysql['host'],$database_mysql['username'],$database_mysql['password'],$database_mysql['dbname']);
$for_statistics_purpose=new pgSQL($database_pgsql['dbms'],$database_pgsql['host'],$database_pgsql['username'],$database_pgsql['password'],$database_pgsql['dbname']);
?>
br/ Page containing CRUD function, (*6)
open();
#or open connection to pgsql
//backup database
$sth=$for_statistics_purpose->open();
?>
br/, (*7)
Developer can create their own module by extending defined class to dbms under the namespace DBCon\dbms and to make cleaner extension add your defined class on dbcon/your_namespace/your_extension_class, (*8)
Example. dbcon/pgsql/pgsql.php, (*9)
Developer A and Developer B conversation, (*10)
Do you need mysql?, (*11)
I have mysql module
Do you need pgsql?, (*12)
Nope! i dont use it and i need a smaller footprint
Fine i will remove pgsql folder :), (*13)
wait! i need mongoDB
SOLUTION: Then Create Module <3, (*14)
br/, (*15)
You can find the PHPUnit tests in dbconUnitTesting folder, (*16)
This software is under the MIT liscense.Please read LICENSE for information on the software availability and description., (*17)