tpojka/rel-sql

Simple DB connector for MySQL and PostgreSQL

dev-main / 0.9.x-dev 2021-08-09 12:32 UTC

This package is auto-updated.

Last update: 2024-04-09 23:16:39 UTC


README

Latest Unstable Version Software License

Package for connecting relational databases such are MySQL or PostgreSql. Code is in development phase until reaches version v1.

Structure

src/
tests/

Install

Via Composer

$ composer require tpojka/rel-sql

Usage

Be sure you have created database

// initialize migrations within project
php vendor/bin/phinx init
// set db credentials in newly created ./phinx.php file

mkdir -p db/migrations db/seeds
php vendor/bin/phinx create MyFirstMigration
php vendor/bin/phinx migrate -e development

// further explanation of how to use phinx can be checked in docs
// @see https://book.cakephp.org/phinx/0/en/contents.html

After you have table set rel-sql package can be used similarly to:

use Tpojka\RelSql\MysqlAdapter;
use Tpojka\RelSql\Db;

$mysqlAdapter = new MysqlAdapter($host, $name, $user, $pass);
$db = new Db($mysqlAdapter);

$db->connect();

$db->setTable('books');

// default is `id`
$db->setPrimaryKey('hungarian_notation_id');

return $db->getAll();

Testing

During tests table test_table will be created

$ composer test

Security

Package is in dev phase and use in production is not advisable.

Credits

License

The MIT License (MIT). Please see License File for more information.