A PHP database handler class based on PDO, the input can be an array or a JSON file, it supports multiple queries, as well. (it works with mariadb and mysql)
Install with composer
- if you use composer you can install it if you add it to your composer.json
- connection parameters
- you can define them like global variables in your config.php
<?php define('DSN', 'host=your_hostname or unix_socket=your_info'); define('DBNAME', 'your_databasename'); define('USERNAME', 'your_username'); define('PASSWORD', 'your_password'); define('PATH', 'your/base/path'); ?>
- or you can declare them in the json file (sample json in the src folder)
Manual install
- you can clone the repository to your hdd or server (git clone git@github.com:zashboy/ZDB.git)
- you need to care about the autoloading for example:
<?php
spl_autoload_register(function($class){
foreach(glob('*/your-path-to-src-folder/src/class.' . $class . '.php') as $config){
require_once ($config);
}
});
?>
- see the 2. in the Install with composer list above
Where you need to get some data from the database and you would start to code the PDO query, you just need to instatiate the ZDB class and give it to your array of the variables or a path to a JSON file which contains all the data what you need.
for example with a JSON file:
<?php
$test = new ZDB(PATH . 'filename.json', '>>currently used section<<', ['getPages' => ['select-1' => ['where' => ['name' => 'disclaimer']]]]);
?>
example with an array
$test = new ZDB(['delete'=>['tableName' => 'websites', 'where'=>['website_id'=>1]],
'insert'=>['tableName' => 'websites', 'values'=>['website_name'=>'jsdkjsakfsa','server_name'=>'dasdadasfas','creation_date'=>'1980-11-23']]]);
If you've got your object you can find all of your responses in the data property
<?php
$test->data; // all of the data in an array;
$test->exception; //caught exceptions
$test->data->exectime //the execution time in microseconds
?>
You can find a detailed documentation on the link below