PHP code example of mezon / pdocrud

1. Go to this page and download the library: Download mezon/pdocrud library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mezon / pdocrud example snippets


$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
$crud->prepare('SELECT * FROM test_table WHERE id > :id');

// result stores array of anonimous object
$result = $crud->execSelect(['id' => '12']);

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

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

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

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