PHP Classes

PDO helper: Connect and access several database types with PDO

Recommend this page to a friend!
  Info   View files Example   View files View files (8)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Ratings Unique User Downloads Download Rankings
StarStarStar 41%Total: 351 All time: 6,989 This week: 488Up
Version License PHP version Categories
pdohelper 1.28The PHP License5.4Databases
Description 

Author

This class can connect and access several database types with PDO.

It provides a wrapper to access databases with PDO like MySQL, sqlsrv, sqlite, pgsql.

Currently it can means to execute functions like create and drop tables, insert and update with if exists key, execute queries with and without transactions.

Picture of Lukasz Józwiak
  Performance   Level  
Name: Lukasz Józwiak <contact>
Classes: 4 packages by
Country: Poland Poland
Age: 45
All time rank: 265362 in Poland Poland
Week rank: 360 Up8 in Poland Poland Up

Example

<?php

/*
 * is simple connector helper with few most used functions
 */

if (!defined('DS')) {
   
define('DS', DIRECTORY_SEPARATOR);
}
if (!
defined('ROOT')) {
   
define('ROOT', realpath(dirname(__FILE__)));
}

$url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https://' . dirname($_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME']) . '/' : 'http://' . dirname($_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME']) . '/';
if (!
defined('HOST')) {
   
define('HOST', $url);
}
define('DBDEBUG',1);

require_once
ROOT.DS.'Library'.DS.'db.php';

$d = new \Library\DB;
       
// for sqlite "localhost" can be relaced with path to database
$d->Connect('mysql', 'database', 'user', 'password', 'localhost');

var_dump($d->db); // << PDO Object


$d->createTable('tested', array(
   
'name VARCHAR(255)',
   
'string VARCHAR(255)'

));

$d->TInsertIF('tested', ['name' => 'info', 'string' => 'text']);
       
// same as
$d->Begin();
$d->InsertIF('tested', ['name' => 'info', 'string' => 'text']);
$d->Commit(); // or $d->Rollback(); on error

$a = $d->db->query('SELECT * FROM tested'); // call PDO fn
var_dump($a->fetchAll(\PDO::FETCH_NAMED));

$d->Tupdate('tested', ['string' => 'changed'], 'where name=?', ['info']);

$d->Tinsertupdate('tested', ['string' => 'other'], 'where name=?', ['none']); // insert if not found or update exists

$q = $d->Select('tested', ['*'], 'WHERE name = ?', ['info']);

var_dump($q);

$d->Query('SELECT * FROM tested'); // like prepare, exec is shotrcut to PDO fn

$d->dropTable('tested');
?>


  Files folder image Files  
File Role Description
Files folder imagelibrary (2 files, 1 directory)
Accessible without login Plain text file test.php Example usage demo

  Files folder image Files  /  library  
File Role Description
Files folder imageDBplugins (5 files)
  Plain text file db.php Class main class
  Plain text file SystemExceptons.php Class exception support helper

  Files folder image Files  /  library  /  DBplugins  
File Role Description
  Plain text file defaultDBplugin.php Class default plugin
  Plain text file mysql.php Class mysql plugin
  Plain text file pgsql.php Class pgsql plugin
  Plain text file sqlite.php Class sqlite plugin
  Plain text file sqlsrv.php Class sqlsrv plugin

 Version Control Unique User Downloads Download Rankings  
 0%
Total:351
This week:0
All time:6,989
This week:488Up
User Ratings User Comments (1)
 All time
Utility:58%StarStarStar
Consistency:58%StarStarStar
Documentation:-
Examples:66%StarStarStarStar
Tests:-
Videos:-
Overall:41%StarStarStar
Rank:3678