PHP Classes

Yorch MyDb: Execute queries on MySQL, SQLServer, PostgreSQL

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
StarStarStarStar 74%Total: 191 All time: 8,583 This week: 68Up
Version License PHP version Categories
yorch-mydb 1.0.2Custom (specified...5PHP 5, Databases
Description 

Author

This package can execute queries on MySQL, SQLServer, PostgreSQL and ODBC.

There is a factory class that can instantiate driver classes that can access different database types.

The same class can also execute prepared queries and return results in arrays by calling the driver classes.

Abstract Class to manage RDBMS (MySQL, MSSQLServer, ODBC, PostgreSQL) connections

Picture of Yorch Ponce
Name: Yorch Ponce <contact>
Classes: 6 packages by
Country: Mexico Mexico
Innovation award
Innovation award
Nominee: 1x

Example

<?php
require 'vendor/autoload.php';

require_once(
'MyDb.class.php');

// Mysql Example
$provider = 'MySQLDb';
$hostname = '';
$username = '';
$password = '';
$dbname = '';

$dbMySQL = MyDb::getInstance($provider, $hostname, $username, $password, $dbname, 3306);

$query = sprintf("SELECT 1 AS %s", $dbMySQL->escape($provider));

// Associate
print_r($dbMySQL->executeCommand($query));

// Enumerate
print_r($dbMySQL->executeCommand($query, null, MyDb::ENUM));

$dbMySQL = null;

// SQL Server Example
$provider = 'SQLServerDb';
$hostname = '';
$username = '';
$password = '';
$dbname = '';

$dbSQLServer = MyDb::getInstance($provider, $hostname, $username, $password, $dbname, 1433);

$query = sprintf("SELECT 1 AS %s", $dbSQLServer->escape($provider));

// Associate
print_r($dbSQLServer->executeCommand($query));

// Enumerate
print_r($dbSQLServer->executeCommand($query, null, MyDb::ENUM));

$dbSQLServer = null;

// ODBC Example
$provider = 'ODBCDb';
$hostname = 'localhost';
$username = '';
$password = '';
$dbname = 'ODBCDSN'; // ODBC Data Source Name

$dbODBC = MyDb::getInstance($provider, $hostname, $username, $password, $dbname, 1);

$query = sprintf("SELECT 1 AS %s", $dbODBC->escape($provider));

// Associate
print_r($dbODBC->executeCommand($query));

// Enumerate
print_r($dbODBC->executeCommand($query, null, MyDb::ENUM));

$dbODBC = null;

// PostgreSQL Example
$provider = 'PostgreSQLDb';
$hostname = '';
$username = '';
$password = '';
$dbname = '';

$dbPgSQL = MyDb::getInstance($provider, $hostname, $username, $password, $dbname, 5432);

$query = sprintf("SELECT 1 AS %s", $dbPgSQL->escape($provider));

// Associate
print_r($dbPgSQL->executeCommand($query));

// Enumerate
print_r($dbPgSQL->executeCommand($query, null, MyDb::ENUM));

$dbPgSQL = null;

// Mysql Singleton Example
$provider = 'MySQLDb';
$hostname = '';
$username = '';
$password = '';
$dbname = '';

$db = MyDb::getConnection($provider, $hostname, $username, $password, $dbname, 3306);

$query = sprintf("SELECT 1 AS %s", $dbMySQL->escape($provider));

// Associate
print_r($dbMySQL->executeCommand($query));

// Clone in not permitted
$dbclone = clone $db;



?>


Details

MyDb

Description

Abstract Class to manage RDBMS (MySQL, MSSQLServer, ODBC, PostgreSQL) connections

Requirements

Developer Documentation

Execute phpdoc -d MyDb/

Installation

Create file composer.json

{

"require": {
    "yorch/mydb": "dev-master"
}

}

Execute composer.phar install

Example

// Mysql Example
$provider = 'MySQLDb';
$hostname = '';
$username = '';
$password = '';
$dbname   = '';

$dbMySQL = MyDb::getInstance($provider, $hostname, $username, $password, $dbname, 3306);  

$query = sprintf("SELECT 1 AS %s", $dbMySQL->escape($provider));

// Associate
print_r($dbMySQL->executeCommand($query));  

// Enumerate
print_r($dbMySQL->executeCommand($query, null, MyDb::ENUM));  

$dbMySQL = null;

Notes

The SQL Server connection only works in MS Windows.

For PostgreSQL the parameters in SQL Query must be $#. example: 'SELECT * FROM MYTABLE WHERE ID = $1 AND DESCRIPTION = $2'

For ODBC connection, if the query insert uses ? parameters throw this error (COUNT field incorrect or syntax error).

Sorry, my english is bad :(.

References

http://es.wikipedia.org/wiki/Patr%C3%B3n_de_dise%C3%B1o

http://es.wikipedia.org/wiki/Singleton

http://es.wikipedia.org/wiki/Abstract_Factory

Donate

Donate

P.D. Let's go play !!!


  Files folder image Files (7)  
File Role Description
Accessible without login Plain text file composer.json Data Auxiliary data
Plain text file DriverDb.class.php Class Class source
Accessible without login Plain text file examples.php Example Example script
Accessible without login Plain text file LICENSE Lic. License
Plain text file MyDb.class.php Class Class source
Accessible without login Plain text file MyDbTest.php Test Unit test script
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:191
This week:0
All time:8,583
This week:68Up
 User Ratings  
 
 All time
Utility:83%StarStarStarStarStar
Consistency:83%StarStarStarStarStar
Documentation:83%StarStarStarStarStar
Examples:83%StarStarStarStarStar
Tests:83%StarStarStarStarStar
Videos:-
Overall:74%StarStarStarStar
Rank:81