Skip to content

DavidPerez-2357/DatabaseMethods

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

303 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DatabaseMethods

A lightweight PHP library that cuts database boilerplate down to its essentials: two focused classes that let you write less and do more.

Compatible with PHP 5.4 and above. MySQL, PostgreSQL, SQLite, and SQL Server supported.

Installation & Usage

Download or clone the repository and require the single entry-point file; it automatically loads every module:

require_once 'DatabaseMethods.php';

No Composer, no external dependencies.

What's inside

Query - SQL builder

Build any SELECT, INSERT, UPDATE, or DELETE with a clean fluent API (or the classic array constructor):

$query = Query::select(['id', 'name'])
    ->from('users')
    ->where('active = :active')
    ->orderBy('name ASC')
    ->limit(20);

SELECT id, name FROM users WHERE active = :active ORDER BY name ASC LIMIT 20

Full Query documentation →


Database - PDO wrapper

Connect once, then select, insert, update, delete, count, and run transactions with no boilerplate:

$db = new Mysql(['serverName' => 'localhost', 'username' => 'root', 'password' => '', 'DB' => 'mydb']);

$users  = $db->select($query, ['active' => 1]);
$lastId = $db->insert('users', ['name' => 'Alice', 'email' => 'alice@example.com']);
$rows   = $db->update('users', ['name' => 'Bob'], 'id = :id', ['id' => $lastId]);

$db->executeTransaction(function($db) {
    $db->delete('orders', 'user_id = :id', ['id' => 5]);
    $db->update('users', ['active' => 0], 'id = :id', ['id' => 5]);
});

Full Database documentation →


PdoParameterBuilder - PDO parameter helper

Static utility for building PDO named-parameter arrays and common SQL fragments. Useful when writing queries by hand or extending the library:

// Build params for a multi-row INSERT
$params = PdoParameterBuilder::buildInsertParams([
    ['name' => 'Alice', 'age' => 30],
    ['name' => 'Bob',   'age' => 25],
]);
// => [':name_0' => 'Alice', ':age_0' => 30, ':name_1' => 'Bob', ':age_1' => 25]

Full PdoParameterBuilder documentation →

Contributing

Contributions are welcome! See CONTRIBUTING.md for local setup instructions, how to run the test suite, and the project's coding guidelines.

License

MIT - see LICENSE.

About

File with useful methods to work with SQL, MySQL, Postgres or SQLite database made in PHP

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages