PHP Classes

mezon PHP PDO CRUD: Execute common database queries using PDO

Recommend this page to a friend!
  Info   Documentation   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: 194 All time: 8,543 This week: 41Up
Version License PHP version Categories
mezon-pdocrud 1.0.0MIT/X Consortium ...5PHP 5, Databases
Description 

Author

This package can execute common database queries using PDO.

The main class can establish a connection to one of many types of databases supported by the PHP PDO extension.

There is also a trait that is able to take a connection string to be validated and calls the main class to establish the connection and return an object of that class.

The main class can also perform common database queries passing a few parameters like:

- Executing a select query on a table that matches certain conditions and returns values of given table fields
- Update the records of a table that match a certain condition with given field values
- Delete records of a table that match a condition
- Lock one or more tables for reading or writing
- Unlock tables
- Starting, commiting and rollback a transaction
- Insert one or more records on a table with given field values
- Get the identifier value of the last field that was inserted

Picture of Alexey Dodonov
  Performance   Level  
Name: Alexey Dodonov <contact>
Classes: 58 packages by
Country: Russian Federation Russian Federation
Age: ???
All time rank: 184954 in Russian Federation Russian Federation
Week rank: 180 Up9 in Russian Federation Russian Federation Up
Innovation award
Innovation award
Nominee: 13x

Documentation

Database support Build Status codecov

Intro

Mezon built-in classes support varios databases using PDO extension of the PHP language.

Detail

The following databases are supported:

  • CUBRID
  • MS SQL Server
  • Firebird
  • IBM
  • Informix
  • MySQL
  • MS SQL Server
  • Oracle
  • ODBC and DB2
  • PostgreSQL
  • SQLite
  • 4D

PDO objects are wrapped with ProCrud class wich will help you to create simple CRUD routine.

For example:

$dataConnection = [
    'dns' => 'mysql:host=localhost;dbname=testdb' , 
    'user' => 'user' ,
    'password' => 'password'
];

$crud = new \Mezon\PdoCrud\PdoCrud();
$crud->connect( $dataConnection );
// fetching fields id and title from table test_table where ids are greater than 12
$records = $crud->select( 'id , title' , 'test_table' , 'id > 12' );

Deleting records

Deleting routine is quite simple:

$crud->delete( 
	'table_name' , // table name
	'id > 10' ,    // WHERE statement
	10             // number of records to delete
);

Inserting records

Inserting routine is also very simple:

$crud->insert( 
	'table_name' ,                 // table name
	array( 'f1' => 1 , f2 => '2' ) // new values for fields f1 and f2
);

Updating records

Updating routine is also very simple:

$crud->update( 
	'table_name' ,                   // table name
	array( 'f1' => 1 , f2 => '2' ) , // new values for fields f1 and f2
	'id > 10'                        // WHERE statement
);

Transaction and thread safety

You can lock tables and work with transactions.

$crud->lockTables( [ 'table1' , 'table2' ] , [ 'READ' , 'WRITE' ] );
$crud->startTransaction();

// perform some changes in database

// then commit these changes
$crud->commit();

// or rollback them
// $crud->commit();

$crud->unlockTables();

  Files folder image Files (9)  
File Role Description
Files folder imageTests (2 files)
Accessible without login Plain text file .travis.yml Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Plain text file ConnectionTrait.php Class Class source
Plain text file PdoCrud.php Class Class source
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (9)  /  Tests  
File Role Description
  Plain text file ConnectionTraitUnitTest.php Class Class source
  Plain text file PdoCrudUnitTest.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:194
This week:0
All time:8,543
This week:41Up