PHP code example of derilkillms / pdo-orm

1. Go to this page and download the library: Download derilkillms/pdo-orm 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/ */

    

derilkillms / pdo-orm example snippets


unset($CFG);
global $CFG;
$CFG = new stdClass();

$CFG->dbdriver  = 'pdo';
$CFG->dbtype    = 'mysql'; //mysql or pgsql
$CFG->dbhost    = 'localhost';
$CFG->dbname    = 'YOUR_DB_NAME';
$CFG->dbuser    = 'root';
$CFG->dbpass    = '';
$CFG->prefix    = 'd_';


$users = $DB->get_records_sql("SELECT * FROM {users} where city=?",array('ciamis')); //for get rows data 

$user = $DB->get_record_sql("SELECT * FROM {user} where id=?",array(1)); // for get row data / one data 

$user = $DB->execute("DELETE FROM {user} WHERE id=?",array(1)); // for execute query like insert update delete


//intialize key and value with object
$data = new stdClass();
$data->name = 'test';
$data->value = 'test';
//insert record
$insert =  $DB->insert_record('table', $data);


$data = new stdClass();
$data->id = 1; //id params is important for update
$data->name = 'tests';
$data->value = 'tests';
//update record
$update =  $DB->update_record('table', $data);
//delete record
$delete = $DB->delete_record('table','id=?',array(7));