coffeebreaks/database

This component connects, registers, reads, edits and deletes records in the database

V1.1.5 2021-04-04 02:02 UTC

This package is auto-updated.

Last update: 2024-11-04 10:12:32 UTC


README

Source Code PHP from Packagist Latest Stable Version License Total Downloads Build Quality Score

COFFEBREAKS/DATABASE

This component connects, registers, reads, edits and deletes records in the database.

Intalation
composer require coffeebreaks/database

Config

Connect with PDO

define('DB', [
    'host' => 'localhost',
    'user' => 'root',
    'pass' => '',
    'name' => 'dbdebug',
    'port' => 3306,
    'driver' => 'mysql', //default = mysql
    'options' => [
        PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
        PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
        PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ
    ]
]);

Creating Model

In the folder app/Models create the class Users

<?php


namespace App\Models;


use Database\Database;

class Users extends Database
{
protected $table = "users";
}

Creating user

use App\Models\Users;

$user = new Users();

$user->name = "Guilherme";
$user->age = 26;

$user->save();


var_dump($user);

Update user

$user = new Users();
$user->id = 1;
$user->name = "Guilherme K.";
$user->age = 26;

$user->save();


var_dump($user);

List all datas

$user = new Users();

var_dump($user->all()->getGet());

FindById

$user = new Users();
$user->findById(1);


var_dump($user->getGet());

FindByEmail

$user = new Users();
$user->findByEmail("email@email.com");


var_dump($user->getGet());

orderBy

$user = new Users();

var_dump($user->all()->orderBy('collumn ASC'));