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: 156 All time: 8,985 This week: 171Up
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: 74721 in Poland Poland
Week rank: 189 Up4 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:156
This week:0
All time:8,985
This week:171Up
User Comments (1)
So basic
2 years ago (keran)
30%StarStar