Easy sql-db connection

v2.0-beta 2022-10-01 03:25 UTC

This package is auto-updated.

Last update: 2024-10-22 05:17:12 UTC


README

CodeFactor

Installation

Github:

git clone https://github.com/Mateodioev/db
cd db
composer install

Composer:

composer require mateodioev/db

Usage

Set database data

use Mateodioev\Db\Connection;

Connection::Prepare('DB_HOST', 'DB_PORT', 'DB_NAME', 'DB_USER', 'DB_PASS');
# or 
$dir = 'path/to/.env/file';
Connection::PrepareFromEnv($dir);

Execute querys

use Mateodioev\Db\Query;
$db = new Query();

// Return one afect row
$db->Exec('SELECT * FROM users'); // Simple sql query
$db->Exec('SELECT * FROM users WHERE id = :id', [':id' => 'random_id']); // With params

// Return all afect rows
$db->GetAll('SELECT * FROM users'); // Simple sql query
$db->GetAll('SELECT * FROM users WHERE id = :id', [':id' => 'random_id']); // With params

Exceptions

  • Connection::PrepareFromEnv($dir); If dir not fund or not readable throw exception

  • $db->Exec($sql_query) or $db->GetAll($sql_query) If sql query not valid or invalid credentials throw exception