PHP code example of william-costa / database-manager

1. Go to this page and download the library: Download william-costa/database-manager 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/ */

    

william-costa / database-manager example snippets




illiamCosta\DatabaseManager\Database;

//DATABASE CREDENTIALS
$dbHost = 'localhost';
$dbName = 'database';
$dbUser = 'root';
$dbPass = 'pass';
$dbPort = 3306;

//CONFIG DATABASE CLASS
Database::config($dbHost,$dbName,$dbUser,$dbPass,$dbPort);

//TABLE INSTANCE
$obDatabase = new Database('table_name');

//SELECT (return a PDOStatement object)
$results = $obDatabase->select('id > 10','name ASC','1','*');

//INSERT (return inserted id)
$id = $obDatabase->insert([
  'name' => 'William Costa'
]);

//UPDATE (return a bool)
$success = $obDatabase->update('id = 1',[
  'name' => 'William Costa2'
]);

//DELETE (return a bool)
$success = $obDatabase->delete('id = 1');




illiamCosta\DatabaseManager\Database;
use WilliamCosta\DatabaseManager\Pagination;

//DATABASE CREDENTIALS
$dbHost = 'localhost';
$dbName = 'database';
$dbUser = 'root';
$dbPass = 'pass';
$dbPort = 3306;

//CONFIG DATABASE CLASS
Database::config($dbHost,$dbName,$dbUser,$dbPass,$dbPort);

//TABLE INSTANCE
$obDatabase = new Database('table_name');

//COUNT TOTAL RESULTS
$totalResults = $obDatabase->select('id > 10',null,null,'COUNT(*) as total')->fetchObject()->total;

//CURRENT PAGE
$currentPage  = $_GET['page'] ?? 1;
$itemsPerPage = 10;

//PAGINATION
$obPagination = new Pagination($totalResults,$currentPage,$itemsPerPage);

//SELECT (return a PDOStatement object)
$results = $obDatabase->select('id > 10',null,$obPagination->getLimit());

//PAGES (array)
$pages = $obPagination->getPages();