PHP Classes

Database class extending PDO: Execute queries composed programatically using PDO

Recommend this page to a friend!
  Info   View files Example   View files View files (22)   DownloadInstall with Composer Download .zip   Reputation   Support forum (3)   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2024-01-09 (5 months ago) RSS 2.0 feedStarStarStarStar 67%Total: 1,634 This week: 2All time: 2,410 This week: 35Up
Version License PHP version Categories
db-pdo 2.0.10GNU General Publi...5.6PHP 5, Databases
Description 

Author

This class can be used to execute queries composed programatically using PDO.

It can connect to a given database using PDO and execute queries composed programmatically.

The class can compose SQL SELECT, INSERT, UPDATE and DELETE queries with parameters passed to functions to define query fields, field values, order fields, group fields, having clause, join fields, and results limit values.

Picture of Jelle Sebreghts
  Performance   Level  
Name: Jelle Sebreghts <contact>
Classes: 7 packages by
Country: United States United States
Age: 34
All time rank: 1485222 in United States United States
Week rank: 34 Up4 in United States United States Up
Innovation award
Innovation award
Nominee: 4x

Example

<?php

require_once '../vendor/autoload.php';
//change these to your database settings
define("DB_HOST", "localhost");
define("DB_NAME", "db_example");
define("DB_USER", "root");
define("DB_PASSWORD", "root");
$db = new Jelle_S\DataBase\Connection("mysql:host=" . DB_HOST . ";dbname=" . DB_NAME, DB_USER, DB_PASSWORD);

$menu = $db->select('menu')->fields(array('label', 'page'))->orderby('weight')->run()->fetchAllAssoc();

print
"Initial data: <br /><pre>";
print_r($menu);
print
"</pre>";

$fields = array(
 
'label' => 'This is the menu label.',
 
'page' => 'home', //e.g relative link to the page'
 
'weight' => 6,
);
$db->insert('menu')->fields($fields)->run();
$last_insert_id = $db->lastInsertId();

$menu = $db->select('menu')->fields(array('label', 'page'))->orderby('weight')->run()->fetchAllAssoc();

print
"Data after insert: <br /><pre>";
print_r($menu);
print
"</pre>";

$updatefields = array(
 
'label' => 'This is the new label.',
 
'page' => 'contact',
 
'weight' => 5
);

$db->update('menu')->fields($updatefields)->where('id', $last_insert_id)->run();

$menu = $db->select('menu')->fields(array('label', 'page'))->orderby('weight')->run()->fetchAllAssoc();

print
"Data after update: <br /><pre>";
print_r($menu);
print
"</pre>";

$db->delete('menu')->where('id', $last_insert_id)->run();

$menu = $db->select('menu')->fields(array('label', 'page'))->orderby('weight')->run()->fetchAllAssoc();

print
"Data after delete: <br /><pre>";
print_r($menu);
print
"</pre>";



Details

db-pdo ======

  Files folder image Files  
File Role Description
Files folder imageexamples (2 files)
Files folder imagesrc (1 file, 2 directories)
Accessible without login Plain text file .codeclimate.yml Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  examples  
File Role Description
  Accessible without login Plain text file db.example.php Example Example script
  Accessible without login Plain text file menu.sql Data Auxiliary data

  Files folder image Files  /  src  
File Role Description
Files folder imageQuery (5 files, 1 directory)
Files folder imageStatement (1 file)
  Plain text file Connection.php Class Class source

  Files folder image Files  /  src  /  Query  
File Role Description
Files folder imageQueryTrait (9 files)
  Plain text file Delete.php Class Class source
  Plain text file Insert.php Class Class source
  Plain text file Query.php Class Class source
  Plain text file Select.php Class Class source
  Plain text file Update.php Class Class source

  Files folder image Files  /  src  /  Query  /  QueryTrait  
File Role Description
  Plain text file Condition.php Class Class source
  Plain text file Fields.php Class Class source
  Plain text file FieldsWithValues.php Class Class source
  Plain text file GroupBy.php Class Class source
  Plain text file Having.php Class Class source
  Plain text file Join.php Class Class source
  Plain text file Limit.php Class Class source
  Plain text file OrderBy.php Class Class source
  Plain text file Where.php Class Class source

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

 Version Control Unique User Downloads Download Rankings  
 100%
Total:1,634
This week:2
All time:2,410
This week:35Up
User Ratings User Comments (2)
 All time
Utility:85%StarStarStarStarStar
Consistency:85%StarStarStarStarStar
Documentation:75%StarStarStarStar
Examples:85%StarStarStarStarStar
Tests:-
Videos:-
Overall:67%StarStarStarStar
Rank:467
 
good job
13 years ago (Ali M.Mirzaee)
70%StarStarStarStar
Excellent work, thank you.
13 years ago (Pali)
70%StarStarStarStar