PHP Classes

File: readme.md

Recommend this page to a friend!
  Classes of Mateo   PHP DB Connection PDO   readme.md   Download  
File: readme.md
Role: Documentation
Content type: text/markdown
Description: Documentation
Class: PHP DB Connection PDO
Query SQL database with parameters from .env files
Author: By
Last change:
Date: 1 year ago
Size: 1,167 bytes
 

Contents

Class file image Download

Easy sql-connection

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