PHP Classes

File: README.md

Recommend this page to a friend!
  Classes of Alexey Dodonov   mezon PHP PDO CRUD   README.md   Download  
File: README.md
Role: Documentation
Content type: text/markdown
Description: Documentation
Class: mezon PHP PDO CRUD
Execute common database queries using PDO
Author: By
Last change:
Date: 3 years ago
Size: 2,051 bytes
 

Contents

Class file image Download

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();