mezon PHP PDO CRUD: Execute common database queries using PDO

Recommend this page to a friend!
  Info   View files Documentation   View files View files (9)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2020-05-09 (4 months ago) RSS 2.0 feedNot enough user ratingsTotal: 129 This week: 2All time: 9,083 This week: 146Up
Version License PHP version Categories
mezon-pdocrud 1.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: 16 packages by
Country: Russian Federation Russian Federation
Innovation award
Innovation award
Nominee: 1x

Details

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  
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  /  Tests  
File Role Description
  Plain text file ConnectionTraitUnitTest.php Class Class source
  Plain text file PdoCrudUnitTest.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:129
This week:2
All time:9,083
This week:146Up

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