PHP Classes
elePHPant
Icontem

The PDM: Run queries and manage tables with PDO or MySQLi

Recommend this page to a friend!
  Info   View files Example   View files View files (23)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2016-11-23 (1 year ago) RSS 2.0 feedNot enough user ratingsTotal: 183 All time: 8,277 This week: 396Up
Version License PHP version Categories
the-pdm 1.0GNU General Publi...5PHP 5, Databases
Description Author

This package can run queries and manage tables with PDO or MySQLi.

It provides classes to execute queries to manipulate table records, or the structure of database tables, or manage table access permissions with separate module classes.

The package provides modules specialized in databases accessed via PDO or MySQL using the MySQLi extension.

  Performance   Level  
Name: Mohamed Elbahja <contact>
Classes: 10 packages by
Country: Morocco Morocco
Innovation award
Innovation award
Nominee: 4x

Details

THE-PDM

THE PDM is a Library to deal with different databases with PDO or mysqli

Usage

Config file

edit PDM_CONFIG_DIR config folder path in : src/PDM/PDM.php

Database Config

Each database can create a setup file in config directory

  • type : Database Book PDO or Mysqli
  • info.host : Database Host name
  • info.name : Databbase name
  • info.user : Database user
  • info.pwd : database password
  • prefix : for security, You can change it at any time
  • charset : db encoding

examples :

Connect MySQL Database via Mysqli

<?php defined('PDM_CONFIG_DIR') || exit;

// Database1.config.php

return array
(
  'type'  => 'mysqli',
  'info'  => array
  (
  	'host'	=> 'localhost',
    'name'	=> 'dbname',
    'user'  => 'root',
    'pwd'   => '',
  ),
  'prefix'    => 'prefix_',
  'charset'   => 'utf8mb4',
);

Connect MySQL Database via PDO

<?php defined('PDM_CONFIG_DIR') || exit;

// Database2.config.php

return array
(
  'type'  => 'pdo:mysql',
  'info'  => array
  (
  	'host'	=> 'localhost',
    'name'	=> 'Dbname',
    'user'  => 'root',
    'pwd'   => '',
  ),
  'prefix'    => 'prefix_',
  'charset'   => 'utf8mb4',
);

Connect SQLite Database via PDO

<?php defined('PDM_CONFIG_DIR') || exit;

// Database3.config.php

return array
(
  'type'  => 'pdo:sqlite',
  'info'  => array
  (
     'host' => NULL,
    'name'  => 'path/to/sqlite.sq3',
    'user'  => NULL,
    'pwd'   => NULL,
  ),
  'prefix'    => 'prefix_',
  'charset'   => NULL,
);

Start PDM Object

/
 * Require PSR-4 Autoloader
 */
require_once(dirname(__FILE__) . '/autoload.php');

/
 * Start PDM Object
 * @var 
 */
$pdm = PDM\PDM::getInstance();

Load SQL Command


// $pdm->load(command, DbConfigName)

$dml = $pdm->load('DML', 'Database1');

$ddl = $pdm->load('DDL', 'Database2');

$dcl = $pdm->load('DCL', 'Database1');
  • DML : data manipulation language, SELECT - INSERT - UPDATE - DELETE
  • DDL : Data definition language, CREATE - DROP - ALTER - RENAME - TRUNCATE
  • DCL : Data control language, GRANT - REVOKE
  • <del>TCL : Transaction Control Language</del>

DML

/
 * Require PSR-4 Autoloader
 */
require_once('path/to/autoload.php');

/
 * Start PDM Object
 * @var 
 */
$pdm = PDM\PDM::getInstance();

/ load DML */
$dml = $pdm->load('DML', 'Database1');

Run Query & DB connection


// start database connecton
$dml->start();

/check database is connected/
// boolean $dml->connect->isConnected();

/get connected database name/
// string|false $dml->connect->getConnectedDatabase();

$query = $dml->connect->query('SELECT ....');

Select Data


/
 * table name is : PrefixKey_users
 */
$users = $dml->getUsers();
// mysqli $users->num_rows
// pdo $users->rowCount();

/
 * table name is : PrefixKey_Users
 */
$users = $pdm->getUsers(null, true);

/
 * Options 
 */
 
$users = $pdm->getUsers(['limit' => 10]);
 
/
 * Escape Data
 */
$id = $dml->connect->escape($_GET['id'], 'int');

$options = array(
	
	'get' 	=> 'first_name, last_name, username',
	'cond'	=> 'WHERE user_id=' . $id,
	'limit'  => 1
);

$users = $dml->getUsers($options);

Select data way 2


$id = (isset($_GET['id'])) ? $_GET['id'] : null;

$id = $dml->connect->escape($id, 'int');
$un = $dml->connect->escape('moh'); // escape string
$users = $dml->select('first_name, last_name...', 'users', "WHERE id=$id AND username='{$un}'");

Select One Row


$user = $dml->selectOne('first_name, last_name', 'users', 'WHERE id=1');

echo $user['last_name'];

Please read the classes doc for more information & examples dir

  Files folder image Files  
File Role Description
Files folder imageExamples (3 files)
Files folder imagesrc (1 directory)
Accessible without login Plain text file autoload.php Aux. Auxiliary script
Accessible without login Plain text file examples.php Example Example script
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Example script

  Files folder image Files  /  Examples  
File Role Description
  Accessible without login Plain text file DCL.php Example Example script
  Accessible without login Plain text file DDL.php Example Example script
  Accessible without login Plain text file DML.php Example Example script

  Files folder image Files  /  src  
File Role Description
Files folder imagePDM (2 files, 5 directories)

  Files folder image Files  /  src  /  PDM  
File Role Description
Files folder imageConfig (3 files)
Files folder imageExceptions (1 file)
Files folder imageInterfaces (2 files)
Files folder imageMysqli (4 files)
Files folder imagePdo (4 files)
  Plain text file Loader.php Class Class source
  Plain text file PDM.php Class Class source

  Files folder image Files  /  src  /  PDM  /  Config  
File Role Description
  Accessible without login Plain text file mysqli.config.php Aux. Auxiliary script
  Accessible without login Plain text file PdoMysql.config.php Aux. Auxiliary script
  Accessible without login Plain text file PdoSqlite.config.php Aux. Auxiliary script

  Files folder image Files  /  src  /  PDM  /  Exceptions  
File Role Description
  Plain text file PDMException.php Class Class source

  Files folder image Files  /  src  /  PDM  /  Interfaces  
File Role Description
  Plain text file Loader.php Class Class source
  Plain text file PDM.php Class Class source

  Files folder image Files  /  src  /  PDM  /  Mysqli  
File Role Description
  Plain text file Connect.php Class Class source
  Plain text file DCL.php Class Class source
  Plain text file DDL.php Class Class source
  Plain text file DML.php Class Class source

  Files folder image Files  /  src  /  PDM  /  Pdo  
File Role Description
  Plain text file Connect.php Class Class source
  Plain text file DCL.php Class Class source
  Plain text file DDL.php Class Class source
  Plain text file DML.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:183
This week:0
All time:8,277
This week:396Up