PHP Classes

PHP Singleton Database Class PDO: Connect to many types of database using PDO

Recommend this page to a friend!
  Info   View files Example   View files View files (4)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 157 This week: 1All time: 8,999 This week: 560Up
Version License PHP version Categories
singletondbconnect 1.0.0MIT/X Consortium ...5PHP 5, Databases, Language
Description 

Author

This class can connect to many types of database using PDO.

It works as a singleton, so when a new object of the class is created multiple times, it returns the same object created in the first time a new class object was created.

The class provides different functions to setup connections to different types of SQL databases. Currently it supports databases like SQLite, MySQL, Microsoft SQL Server and PostgreSQL .

Picture of adam berger
  Performance   Level  
Name: adam berger <contact>
Classes: 23 packages by
Country: Poland Poland
Age: ???
All time rank: 74621 in Poland Poland
Week rank: 52 Up3 in Poland Poland Up
Innovation award
Innovation award
Nominee: 8x

Winner: 2x

Example

<?php
       
require 'SingletonDB.php';

         try {
           
          
// $singletonDB = SingletonDB::getInstance()->connectMysql();
       // $singletonDB = SingletonDB::getInstance()->connectMicrosoftSqlServer();
           // $singletonDB = SingletonDB::getInstance()->connectPostgreSql();
        
          
$singletonDB = SingletonDB::getInstance()->connectSQLite();
         
$query = "SELECT `nameUser` FROM `testwielki`";
        
// $result = $singletonDB->prepare($query);
         
$result = $singletonDB->query($query);
         
$result->execute();
         
$as = $result->fetchAll();
                 
print_r($as);
             echo
count($result->fetchAll());
            
       if(
$result->rowCount() > 0){
         
$as = $result->fetchAll();
               
print_r($as);
        
$result->closeCursor();
           }
         } catch (
Exception $ex) {
             
$mesage1 = " ";
         echo
$mesage1 .= $ex->getTraceAsString()
                .
$ex->getMessage().'<br />'
               
.$ex->getCode().'<br />'
               
.$ex->getFile().'<br />'
               
.$ex->getLine().'<br />'
               
.$ex->getPrevious();
         } catch(
PDOException $ep){
                 
$mesage1 = " ";
             echo
$mesage1 .= $ep->getTraceAsString()
                .
$ep->getMessage().'<br />'
               
.$ep->getCode().'<br />'
               
.$ep->getFile().'<br />'
               
.$ep->getLine().'<br />'
               
.$ep->getPrevious();
             }


Details

SingletonDBConnect

Po??czenie singleton PHP PDO do wielu baz danych


  Files folder image Files  
File Role Description
Plain text file ClassSingletonDB.php Class Class source
Accessible without login Plain text file index.php Example Example script
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation

 Version Control Unique User Downloads Download Rankings  
 100%
Total:157
This week:1
All time:8,999
This week:560Up
User Comments (1)
So basic
2 years ago (keran)
30%StarStar