PHP Classes

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

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: 191 All time: 8,581 This week: 455Up
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.

Picture of Mohamed Elbahja
  Performance   Level  
Name: Mohamed Elbahja is available for providing paid consulting. Contact Mohamed Elbahja .
Classes: 12 packages by
Country: Morocco Morocco
Age: 29
All time rank: 9011 in Morocco Morocco
Week rank: 192 Up2 in Morocco Morocco Down
Innovation award
Innovation award
Nominee: 4x

Example

<?php

require_once(dirname(__FILE__) . '/autoload.php');

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

/**
 * Load Command
 * @var oject
 */
$dml = pdm->load('DML', 'Database1');

/** start connection **/
$dml->start();

/**
 * Select DATA
 * table name is : prefix_users
 */
$users = $dml->getUsers();

/** table : prefix_pages **/
$pages = $dml->getPages();


/** Left Join **/
//$data = $dml->select('@prefix_tableName.id, @prefix_tableNameTwo.user', 'tableName', 'LEFT JOIN @prefix_tableNameTwo ON @prefix_tableName.id=@prefix_tableNameTwo.uid');


/** DDL **/
$ddl = $pdm->load('DDL', 'Database1');
$ddl->start();

$c = $ddl->create('tableName', '(id int NOT NULL PRIMARY KEY,
    name varchar(122) COLLATE @charset_general_ci NOT NULL,
    username varchar(50) COLLATE @charset_general_ci NOT NULL);'
)); // @charset = default charset in config file

var_dump($c);


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 (23)  
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 (23)  /  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 (23)  /  src  
File Role Description
Files folder imagePDM (2 files, 5 directories)

  Files folder image Files (23)  /  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 (23)  /  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 (23)  /  src  /  PDM  /  Exceptions  
File Role Description
  Plain text file PDMException.php Class Class source

  Files folder image Files (23)  /  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 (23)  /  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 (23)  /  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

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,581
This week:455Up