DB Manager Logger: Execute and log MySQL queries using PDO

Recommend this page to a friend!
  Info   Screenshots Screenshots   View files View files (83)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 327 All time: 7,071 This week: 245Up
Version License PHP version Categories
db-manager-logger 2.2.3GNU General Publi...5.4PHP 5, Databases, Logging
Description Author

This package can compose and execute MySQL queries using PDO.

It provides several functions to compose SQL SELECT, INSERT, UPDATE and DELETE queries from given parameter values that define table names, field names and values, conditions, etc..

The main class can also manage start, commit and revert transactions.

A separate class can log the executed database operations.

Picture of Victor Henrique Pereira
  Performance   Level  
Name: Victor Henrique Pereira <contact>
Classes: 2 packages by
Country: Brazil Brazil
Age: 29
All time rank: 2089136 in Brazil Brazil
Week rank: 633 Up46 in Brazil Brazil Up

Details

Database Manager

<p>This class provides a safe connection with database (yeah, it does use transaction) and log all actions performed daily into a single file/day.</p> <p>You can audit all queries was performed into database, with values, datetime and totally debugged by viewing the files created into ./log/ folder.</p>

Total Downloads Latest Unstable Version Latest Stable Version License

License

<p>This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.</p>

<p>This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.</p>

<p>You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.</p>

Installation

Execute the sql file located in `./src/`

Install [apache/log4php] using [composer].

To install, add `apache/log4php` to your `composer.json` file.

{
   "require" : {
    "apache/log4php": "2.3.0"
  },
}

From there, use the `composer install` or `composer update` commands to install.

Basic Usage

<?php
define('DB_HOST', 'my-host'); // define the host of mysql server
define('DB_PORT', 3306); // define the port of mysql server
define('DB_USER', 'my-user'); // define the user of mysql server
define('DB_PASS', 'my-pass'); // define the password of mysql server
define('DB_NAME', 'my-db'); // define the database name
define('DB_ENCODING', 'utf8'); // define the encoding of statements

// Assuming you installed from Composer:
require "vendor/autoload.php";

// Get the instance of DBManager:
$pdo = DBManager::getInstance();

###### INSERT STATEMENT ######
// Array with key->val pairs (columns that will be created)
$paramIns = array(
    'cn1' => 'cv1',
    'cn2' => 'cv2',
    'cnN' => 'cvN',
);
// Creates the sql
$insert = $pdo->createInsert('tableName', $paramIns);
/*
Output: INSERT INTO tableName(cn1,cn2,cnN) VALUES (:cn1,:cn2,:cnN);
*/
$resultInsert = $pdo->query($insert);

###### UPDATE STATEMENT ######
// Array with key->val pairs (columns that will be updated)
$paramUpd = array(
    'cn1' => 'cv1',
    'cn2' => 'cv2'
);
// Array with columnKey => val (columns that will be used on WHERE clause)
// If null or empty, the result sql will be "UPDATE tableName SET col1 = :val1, col2 = :va2, ... colN = :valN ;"
$paramCond = array(
	// The first parameter of array data is the where clause (like, equal, less, etc... [see the main class constants]])
	// The second parameter of second array is the operand type (and|or) to concat with next column. Use null if the last param
    'ck1' => array(DBManager::COL_EQUAL => array('cv1' => 'and')),
    'ck2' => array(DBManager::COL_EQUAL => array('cv2' => null))
);
// Creates the sql
$update = $pdo->createUpdate('tableName', $paramUpd, $paramCond);
/*
Output: UPDATE tableName SET `cn1` = :cn1, `cn2` = :cn2 WHERE `ck1` = :ck1 and `ck2` =  :ck2 ;
*/
$resultUpdate = $pdo->query($update);

###### DELETE STATEMENT ######
// Array with key->val pairs to where clause to delete
// If null or empty, the result sql will be "DELETE FROM tableName;"
$paramDel = array(
	// The first parameter of array data is the where clause (like, equal, less, etc... [see the main class constants]])
	// The second parameter of second array is the operand type (and|or) to concat with next column. Use null if the last param
	'ck1' => array(DBManager::COL_EQUAL => array('cv1' => null))
);
$delete = $pdo->createDelete('tableName', $paramDel);
/*
Output: DELETE FROM table WHERE  `key1` =  :key1;
*/
$resultDelete = $pdo->query($delete);

###### SELECT STATEMENT ######
// Array with columns to retrieve
$paramSelect = array('cn1', 'cnN');
// Array with columnKey => value to where clause to select
// If null or empty, the result sql will be "SELECT col1, col2,... colN FROM tableName ORDER BY col1,col2,...colN;"
$paramWhere = array(
	// The first parameter of array data is the where clause (like, equal, less, etc... [see the main class constants]])
	// The second parameter of second array is the operand type (and|or) to concat with next column. Use null if the last param
    'cn1' => array(DBManager::COL_EQUAL => array('cv1' => 'and')),
    'cn2' => array(DBManager::COL_LIKE => array('cv2' => null))
);
// Array with columnKey -> value to order clause to select
// If null or empty, the result sql will be "SELECT col1, col2,... colN FROM tableName;"
$paramOrder = array(
	// Fields used in order
    'fields' => array('cn1', 'cn2'),
	// Order type (asc|desc)
    'order' => 'ASC'
);
// Creates the sql
$select = $pdo->createSelect('tableName', $paramSelect, $paramWhere, $paramOrder);
/*
Output: SELECT `cn1`, `cnN` FROM table WHERE `cn1` = :cn1 and `cn2` LIKE :cn2 ORDER BY cn1,cn2 ASC;
*/  
$resultSelect = $pdo->select($select);  
  
unset($pdo);  
?>  

Screenshots

Logger HTML view Logger FILE view

[apache/log4php]:http://logging.apache.org/log4php/download.html [composer]:http://getcomposer.org/

Screenshots  
  • Screenshot_2.png
  Files folder image Files  
File Role Description
Files folder imagephpdoc (2 files, 9 directories)
Files folder imagesrc (2 files, 4 directories)
Files folder imagevendor (1 file, 2 directories)
Files folder imageviews (2 files)
Accessible without login Plain text file composer.json Conf. Composer dependencies
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file config.xml Data Config for the logger
Accessible without login Plain text file index.php Example Index page of testing class
Accessible without login Plain text file LICENSE Lic. Auxiliary data
Accessible without login Plain text file README.md Doc. Auxiliary data

  Files folder image Files  /  phpdoc  
File Role Description
Files folder imageclasses (5 files)
Files folder imagecss (5 files, 1 directory)
Files folder imagefiles (6 files)
Files folder imagefont (1 file)
Files folder imagegraphs (1 file)
Files folder imageimages (12 files, 1 directory)
Files folder imagejs (10 files)
Files folder imagenamespaces (1 file)
Files folder imagereports (3 files)
  Accessible without login Plain text file .htaccess Data Auxiliary data
  Accessible without login HTML file index.html Doc. Documentation

  Files folder image Files  /  phpdoc  /  classes  
File Role Description
  Accessible without login HTML file Accounts.html Doc. Documentation
  Accessible without login HTML file AccountsLogger.html Doc. Documentation
  Accessible without login HTML file DatabaseException.html Doc. Documentation
  Accessible without login HTML file DBManager.html Doc. Documentation
  Accessible without login HTML file DBManagerLogger.html Doc. Documentation

  Files folder image Files  /  phpdoc  /  css  
File Role Description
Files folder imagephpdocumentor-clean-icons (2 files)
  Accessible without login Plain text file bootstrap-combined.no-icons.min.css Data Auxiliary data
  Accessible without login Plain text file font-awesome.min.css Data Auxiliary data
  Accessible without login Plain text file jquery.iviewer.css Data Auxiliary data
  Accessible without login Plain text file prism.css Data Auxiliary data
  Accessible without login Plain text file template.css Data Auxiliary data

  Files folder image Files  /  phpdoc  /  css  /  phpdocumentor-clean-icons  
File Role Description
  Accessible without login Plain text file lte-ie7.js Data Auxiliary data
  Accessible without login Plain text file style.css Data Auxiliary data

  Files folder image Files  /  phpdoc  /  files  
File Role Description
  Accessible without login HTML file index.html Doc. Documentation
  Accessible without login Plain text file index.php.txt Doc. Documentation
  Accessible without login HTML file src.Accounts.class.html Doc. Documentation
  Accessible without login HTML file src.Accounts.logger.html Doc. Documentation
  Accessible without login HTML file src.Database.class.html Doc. Documentation
  Accessible without login HTML file src.Database.exception.html Doc. Documentation

  Files folder image Files  /  phpdoc  /  font  
File Role Description
  Accessible without login Plain text file fontawesome-webfont.svg Data Auxiliary data

  Files folder image Files  /  phpdoc  /  graphs  
File Role Description
  Accessible without login HTML file class.html Doc. Documentation

  Files folder image Files  /  phpdoc  /  images  
File Role Description
Files folder imageiviewer (8 files)
  Accessible without login Image file apple-touch-icon-114x114.png Icon Icon image
  Accessible without login Image file apple-touch-icon-72x72.png Icon Icon image
  Accessible without login Image file apple-touch-icon.png Icon Icon image
  Accessible without login Plain text file custom-icons.svg Data Auxiliary data
  Accessible without login Image file favicon.ico Data Auxiliary data
  Accessible without login Image file hierarchy-item.png Icon Icon image
  Accessible without login Image file icon-class-13x13.png Icon Icon image
  Accessible without login Plain text file icon-class.svg Data Auxiliary data
  Accessible without login Image file icon-interface-13x13.png Icon Icon image
  Accessible without login Plain text file icon-interface.svg Data Auxiliary data
  Accessible without login Image file icon-trait-13x13.png Icon Icon image
  Accessible without login Plain text file icon-trait.svg Data Auxiliary data

  Files folder image Files  /  phpdoc  /  images  /  iviewer  
File Role Description
  Accessible without login Image file grab.cur Data Auxiliary data
  Accessible without login Image file hand.cur Data Auxiliary data
  Accessible without login Image file iviewer.rotate_left.png Icon Icon image
  Accessible without login Image file iviewer.rotate_right.png Icon Icon image
  Accessible without login Image file iviewer.zoom_fit.png Icon Icon image
  Accessible without login Image file iviewer.zoom_in.png Icon Icon image
  Accessible without login Image file iviewer.zoom_out.png Icon Icon image
  Accessible without login Image file iviewer.zoom_zero.png Icon Icon image

  Files folder image Files  /  phpdoc  /  js  
File Role Description
  Accessible without login Plain text file bootstrap.min.js Data Auxiliary data
  Accessible without login Plain text file html5.js Data Auxiliary data
  Accessible without login Plain text file jquery-1.11.0.min.js Data Auxiliary data
  Accessible without login Plain text file jquery.dotdotdot-1.5.9.js Data Auxiliary data
  Accessible without login Plain text file jquery.dotdotdot-1.5.9.min.js Data Auxiliary data
  Accessible without login Plain text file jquery.iviewer.js Data Auxiliary data
  Accessible without login Plain text file jquery.iviewer.min.js Data Auxiliary data
  Accessible without login Plain text file jquery.mousewheel.js Data Auxiliary data
  Accessible without login Plain text file jquery.smooth-scroll.js Data Auxiliary data
  Accessible without login Plain text file prism.min.js Data Auxiliary data

  Files folder image Files  /  phpdoc  /  namespaces  
File Role Description
  Accessible without login HTML file default.html Doc. Documentation

  Files folder image Files  /  phpdoc  /  reports  
File Role Description
  Accessible without login HTML file deprecated.html Doc. Documentation
  Accessible without login HTML file errors.html Doc. Documentation
  Accessible without login HTML file markers.html Doc. Documentation

  Files folder image Files  /  src  
File Role Description
Files folder imageinterfaces (1 file)
Files folder imageloggers (1 file)
Files folder imagemain (3 files)
Files folder imagemodels (1 file)
  Plain text file Database.class.php Class Main class source
  Plain text file Database.exception.php Class Class exception helper

  Files folder image Files  /  src  /  interfaces  
File Role Description
  Plain text file IModels.php Class Class source

  Files folder image Files  /  src  /  loggers  
File Role Description
  Plain text file Accounts.logger.php Class Class source

  Files folder image Files  /  src  /  main  
File Role Description
  Plain text file DBLogger.class.php Class Class source
  Plain text file DBManager.class.php Class Class source
  Plain text file DBManager.exception.php Class Class source

  Files folder image Files  /  src  /  models  
File Role Description
  Plain text file Accounts.class.php Class Class source

  Files folder image Files  /  vendor  
File Role Description
Files folder imagebin (2 files)
Files folder imagecomposer (8 files)
  Accessible without login Plain text file autoload.php Aux. Auxiliary script

  Files folder image Files  /  vendor  /  bin  
File Role Description
  Accessible without login Plain text file phpunit Data Auxiliary data
  Accessible without login Plain text file phpunit.bat Data Auxiliary data

  Files folder image Files  /  vendor  /  composer  
File Role Description
  Accessible without login Plain text file autoload_classmap.php Aux. Auxiliary script
  Accessible without login Plain text file autoload_files.php Aux. Auxiliary script
  Accessible without login Plain text file autoload_namespaces.php Aux. Auxiliary script
  Accessible without login Plain text file autoload_psr4.php Aux. Auxiliary script
  Accessible without login Plain text file autoload_real.php Aux. Auxiliary script
  Plain text file ClassLoader.php Class Class source
  Accessible without login Plain text file include_paths.php Aux. Auxiliary script
  Accessible without login Plain text file installed.json Data Auxiliary data

  Files folder image Files  /  views  
File Role Description
  Accessible without login Image file screenshot.png Data Auxiliary data
  Accessible without login Image file screenshot2.png Data Auxiliary data

 Version Control Unique User Downloads Download Rankings  
 96%
Total:327
This week:0
All time:7,071
This week:245Up

For more information send a message to info at phpclasses dot org.