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 (4 days ago) RSS 2.0 feedStarStarStarStar 65%Total: 1,628 This week: 3All time: 2,417 This week: 154Up
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  
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

 Version Control Unique User Downloads Download Rankings  
 100%
Total:1,628
This week:3
All time:2,417
This week:154Up
User Ratings User Comments (2)
 All time
Utility:93%StarStarStarStarStar
Consistency:93%StarStarStarStarStar
Documentation:-
Examples:93%StarStarStarStarStar
Tests:-
Videos:-
Overall:65%StarStarStarStar
Rank:782
 
good job
12 years ago (Ali M.Mirzaee)
70%StarStarStarStar
Excellent work, thank you.
12 years ago (Pali)
70%StarStarStarStar