erykai/database

Responsible for making CRUD with database, using PDO, compatible with: Cubrid, FreeTDS / Microsoft SQL Server / Sybase, Firebird, IBM DB2, IBM Informix Dynamic Server, MySQL 3.x/4.x/5.x, Oracle Call Interface, ODBC v3 (IBM DB2, unixODBC and win32 ODBC), PostgreSQL, SQLite 3 and SQLite 2, Microsoft S

Fund package maintenance!
Erykai

v1.4.7 2023-04-12 20:00 UTC

This package is auto-updated.

Last update: 2024-10-12 23:26:14 UTC


README

Maintainer Source Code PHP from Packagist Latest Version Software License Quality Score Total Downloads

Responsible for making CRUD with database, using PDO, compatible with: Cubrid, FreeTDS / Microsoft SQL Server / Sybase, Firebird, IBM DB2, IBM Informix Dynamic Server, MySQL 3.x/4.x/5.x, Oracle Call Interface, ODBC v3 (IBM DB2, unixODBC and win32 ODBC), PostgreSQL, SQLite 3 and SQLite 2, Microsoft SQL Server / SQL Azure e MariaDB

Installation

Composer:

"erykai/database": "1.1.*"

Terminal

composer require erykai/database

Create Model.php

namespace Erykai\Database;

class Users extends Database
{
    public function __construct()
    {
        parent::__construct(
            'users',
            ['name', 'email', 'age'],
            'id'
        );
    }
}

Constants

const CONN_USER = 'root';
const CONN_PASS = 'root';
const CONN_BASE = 'erykai';
const CONN_HOST = 'mysql';
const CONN_DSN = 'mysql';

CREATE

use Erykai\Database\Users;
require "test/config.php";
require "vendor/autoload.php";

$user = new Users();
$user->name = "Alex de Oliveira Vidal";
$user->email = "teste@webav.com.br";
$user->password = "102asda030";
$user->age = 10;
$user->save();
var_dump($user->response(), $user->data());

READ

use Erykai\Database\Users;

require "vendor/autoload.php";

$Users = new Users();

//RETURN ALL
$users = $Users->find()->fetch(true);
foreach ($users as $user) {
    echo "O $user->name existe!</br>";
}

//RETURNS THE FIRST RESULT FOUND
$user = $Users->find()->fetch();
echo "O $user->name existe!</br>";

//RETURNS THE FIRST RESULT OF THE QUERY
$user = $Users->find('name, email', 'name=:name', ['name'=>'Leonardo'])->fetch();
echo "O $user->name existe!</br>";

//RETURNS ALL QUERY RESULTS
$users = $Users->find('name, email', 'name=:name', ['name'=>'Leonardo'])->fetch(true);
foreach ($users as $user) {
    echo "O $user->name existe!</br>";
}

//RETURNS ALL QUERY RESULTS IN ORDER
$users = $Users
    ->find('name, email', 'name=:name', ['name'=>'Leonardo'])
    ->order("email", "DESC")
    ->fetch(true);
foreach ($users as $user) {
    echo "O $user->name existe!</br>";
}

//RETURNS QUERY RESULTS LIMIT
$users = $Users
    ->find('name, email', 'name=:name', ['name'=>'Leonardo'])
    ->limit(2)
    ->fetch(true);
foreach ($users as $user) {
    echo "O $user->name existe!</br>";
}

//RETURNS QUERY RESULTS LIMIT USING OFFSET
$users = $Users
    ->find('name, email', 'name=:name', ['name'=>'Leonardo'])
    ->limit(2)
    ->offset(2)
    ->fetch(true);
foreach ($users as $user) {
    echo "O $user->name existe!</br>";
}

//RETURNS GROUPED QUERY RESULTS
$users = $Users
    ->find('name, email', 'name=:name', ['name'=>'Leonardo'])
    ->group('name')
    ->fetch(true);
foreach ($users as $user) {
    echo "O $user->name existe!</br>";
}

//RETURNS RESULTS FROM MORE THAN ONE TABLE
$users = $Users
    ->find('name, email, address', 'name=:name', ['name'=>'Leonardo'])
    ->inner('INNER JOIN address ON id_user = users.id')
->fetch(true);
foreach ($users as $user) {
    echo "O $user->name existe e mora reside no endereço: $user->address!</br>";
}

//response
var_dump($Users->response());

UPDATE

use Erykai\Database\Users;
require "test/config.php";
require "vendor/autoload.php";

$user = new Users();
$email = "absurtds@leite.com";
$user->find('*', 'email=:email',['email'=>$email])->fetch();
$users = $user->data();
$users->email = "banana@baasdasdn.cm";
$user->save();
var_dump($user->response());

UPDATE ALL

use Erykai\Database\Users;
require "test/config.php";
require "vendor/autoload.php";

$updateAll = new Users();
$updateAlls = $updateAll->find('email', 'email=:email', ['email'=>'banana@baasdasdn.cm'])->fetch(true);

foreach ($updateAll->data() as $userUpdate) {
    $user = new Users();
    $email = $userUpdate->email;
    $user->find('*', 'email=:email',['email'=>$email])->fetch();
    $users = $user->data();
    $users->email = "asdasdasd@asdasdasd.com";
    $user->save();
    var_dump($user->response());
}

DELETE

use Erykai\Database\Users;
require "test/config.php";
require "vendor/autoload.php";

$user = new Users();
$user->find('id, name', 'id=:id', ['id'=>6])->fetch();
$data = $user->data();
$user->delete($data->id);
var_dump($user->response());

DELETE ALL

use Erykai\Database\Users;
require "test/config.php";
require "vendor/autoload.php";

$removeAll = new Users();
$removeAlls = $removeAll->find('id', 'email=:email',['email'=> 'id2@leite.com'])->fetch(true);
foreach ($removeAll->data() as $userDel) {
    $user = new Users();
    $user->find('id, name', 'id=:id', ['id'=>$userDel->id])->fetch();
    $data = $user->data();
    $user->delete($data->id);
    var_dump($user->response());
}

Contribution

All contributions will be analyzed, if you make more than one change, make the commit one by one.

Support

If you find faults send an email reporting to webav.com.br@gmail.com.

Credits

License

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