PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Mateo   PHP DB Connection PDO   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP DB Connection PDO
Query SQL database with parameters from .env files
Author: By
Last change:
Date: 2 years ago
Size: 567 bytes
 

Contents

Class file image Download
<?php require __DIR__ . '/vendor/autoload.php';

use
Mateodioev\Db\Connection;
use
Mateodioev\Db\Query;

// use Mateodioev\Db\{Connection, Query}; # PHP 8

// Connection::Prepare('host', 'port', 'dbname', 'user', 'pass');
try {
 
Connection::PrepareFromEnv(__DIR__); # Load from .env file
 
$db = new Query;

 
var_dump($db->Exec('SELECT 1+2+3'));
 
var_dump($db->GetAll('SELECT :nums', ['nums' => '1+2+3']));
 
var_dump($db->Ping()); // Verify if the connection is still alive

 
$db->Close();
 
var_dump($db);
 
} catch (
Exception $e) {
  die(
$e->getMessage());
}