PHP code example of coffeebreaks / database

1. Go to this page and download the library: Download coffeebreaks/database library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

coffeebreaks / database example snippets


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




namespace App\Models;


use Database\Database;

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

use App\Models\Users;

$user = new Users();

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

$user->save();


var_dump($user);

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

$user->save();


var_dump($user);

$user = new Users();

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

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


var_dump($user->getGet());

$user = new Users();
$user->findByEmail("[email protected]");


var_dump($user->getGet());

$user = new Users();

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