PHP Classes

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

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 159 All time: 8,987 This week: 39Up
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: 74521 in Poland Poland
Week rank: 216 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 (4)  
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

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:159
This week:0
All time:8,987
This week:39Up
User Comments (1)
So basic
3 years ago (keran)
30%StarStar