PHP Classes

Yorch MyDb: Execute queries on MySQL, SQLServer, PostgreSQL

Recommend this page to a friend!
  Info   View files Example   View files View files (7)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 189 This week: 1All time: 8,601 This week: 560Up
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
Age: 42
All time rank: 206022 in Mexico Mexico
Week rank: 411 Up8 in Mexico Mexico Up
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  
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

 Version Control Unique User Downloads Download Rankings  
 100%
Total:189
This week:1
All time:8,601
This week:560Up