Skip to content

Guilherme-fagundes/database

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 protected]");


var_dump($user->getGet());

orderBy

$user = new Users();

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