prismo-smartpro/datalayer

PDO Datalayer Abstract

2.9 2024-03-03 13:21 UTC

This package is auto-updated.

Last update: 2024-10-03 14:26:10 UTC


README

INSTALAÇÃO

run

composer require prismo-smartpro/datalayer

MYSQL CONNECT

<?php
const MYSQL = [
    "host" => "",
    "username" => "",
    "password" => "",
    "db" => ""
];

DOCUMENTAÇÃO

PHP Class
<?php

namespace SmartPRO\Technology;

class Settings extends DataLayer
{
    public function __construct()
    {
        parent::__construct("settings", "id", $required = [], $unique = [], true);
    }
}

Usage examples

<?php

require "Mysql_Config.php";
require "vendor/autoload.php";

use SmartPRO\Technology\Settings;

// Returns all data from the table
$results = (new Settings())->fetchAll();

// Returns data starting from a specific id
$byId = (new Settings())->findById(17);

// Edit the data that returns and saves the data
if (!empty($byId)) {
    $byId->empresa = "My Business";
    $byId->save();
}

// Deletes the returned query from the database
if (!empty($byId)) {
    $byId->destroy();
}

// Makes a search query using the LIKE parameter
$search = (new Settings())->search("empresa like :empresa", ":empresa=My Business");

// Query with custom data
$results = (new Settings())->find("empresa = :empresa", ":empresa=My Business", "*")
    ->limite(5)
    ->order("id DESC")
    ->gruopBy("site")
    ->offset(0)
    ->fetch(true);

foreach ($results as $result){
    //...
}

PERSONALIZED

<?php

namespace SmartPRO\Technology;

class Settings extends DataLayer
{
    public function __construct()
    {
        parent::__construct("settings", "id", $required = [], $unique = [], true);
    }
    
    public function fidByEmail($email){
        return $this->find("email = :email", ":email={$email}")->fetch();
    }
}