kroyxlab/datbazo

DatBazo(Datuma Bazo, Database in Esperanto) is a SQL-query constructor using PDO.

1.2.0 2019-04-14 17:23 UTC

This package is auto-updated.

Last update: 2025-06-16 09:46:28 UTC


README

DatBazo

DatBazo(Datuma Bazo, Database in Esperanto) is a SQL-query constructor using PDO. is a small library with which you can quickly create queries to the database using the "Prepare" and "Execute" methods of PDO to avoid sql injections.

Table of contents

  1. Dependencies
  2. Install
  3. Getting started
  4. Methods
  5. Author
  6. License

Dependencies

This package requires PHP 7 or higher.

Install

via composer

composer require kroyxlab/datbazo

Copy repository

Copy the direct repository to your project and require the class.

require_once 'proyect_directory/datbazo/src/DatBazo.php';
use kroyxlab\datbazo\DatBazo as DatBazo;

Getting started

Modify the KLPdo.ini file located in the folder vendor/kroyxlab/datbazo/src/DBconfig.ini and modify the values to configure the connection to the database.

[databazo]
db_driver = Mysql || sqlite3 || pgsql
db_host = Host_name
db_port = Port
db_name = Database_name
db_user = user
db_password = password
db_charset = UTF8

If everything is configured correctly, you can start using the library.

require_once "vendor/autoload.php";
use kroyxlab\datbazo\DatBazo as DatBazo;

// instantiate the DatBazo class
$productos = new DatBazo;

// Create an SQL statement using the methods of the KLPdo class
$products->select(['products'=>'name, price'])
          ->where(['price'=>['>=', 12.5]])
          ->order('price')
          ->execute();

// Set the type of fetch you want.
$products->fetch('assoc');

// Use the Method -> render (); to output and format the result of the sql query
$products->render(function($product){

  return "<p>The name of the product is {$product['name']} and the price is {$product['price']}</p>";

});

// Or use a foreach loop using the fetch method

foreach($products->fecth('obj') as $product){
  echo "<p>The name of the product is $product->name and the price is $product->price</p>"
}

Methods

The methods of the DatBazo class help to create an SQL statement which will be executed through the prepare and execute methods of Pdo to avoid SQL injections.

List of methods:

Author

License

This project is licensed under the MIT License - see the MIT.md file for details