PHP Classes
elePHPant
Icontem

File: index.php

Recommend this page to a friend!
  Classes of Dmitry Maltsev  >  Revolver DBX  >  index.php  >  Download  
File: index.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Revolver DBX
Compose MySQLi queries based on parameter values
Author: By
Last change: v.1.1.1 File based DB cache, INJECT querires added, optimizations
Date: 11 months ago
Size: 6,235 bytes
 

Contents

Class file image Download

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>DBX Examples Page and UNIT TESTS | CyberX.pro</title>

    <style type="text/css">
        body, html {
            padding: 0;
            margin: 0;
            background: #f0f0f0;
            font: normal 14px Verdana;
        }
        main {
            width: 1110px;
            margin: 0 auto;
        }

        h1 {
            color: darkgreen;
        }

        h2 {
            color: orange;
        }

        p {
            color: #999;
        }
    </style>

</head>
<body>

    <main>

<?php

// DEBUG
ini_set('error_reporting', E_ALL);

// CONNECT DB
require_once './DBX.php';

// DB connection data
// [0] - host
// [1] - username
// [2] - password
// [3] - database name
// [4] - port
$dbx_data = ['localhost', 'root', 'root', 'dbx_test', '8889'];

// New DBX instance
$dbx = new DBX($dbx_data);

?>

<h1>[1] Example `create table` DBX structure</h1>
<section>

<?php
/**
  * CREATE TABLE EXAMPLE
  */

$table_1 = 'example'; // table name
$query_1 = 'c'; // create table sql

$fields_1 = [
   
'field_id' => [
       
'type' => 'num', // int
       
'auto' => true, // auto increment
       
'length' => 255,
       
'fill' => true // not null
   
],
   
'field_text' => [
       
'type' => 'text', // varchar
       
'length' => 255,
       
'fill' => true
   
],
   
'field_date' => [
       
'type' => 'time', // TIMESTAMP
       
'value' => date('Y-m-d')
    ]
];

// perform queries
$dbx::query($query_1, $table_1, $fields_1);

?>

<?php
   
// print structure
   
print '<h2>DBX STRUCTURE</h2>';
    print
'<pre><code>';
   
print_r( $fields_1 );
    print
'</code></pre>';

   
// print result
   
print '<h2>DBX QUERY RESULT</h2>';
    print
'<pre><code>';
   
print_r( $dbx::$result );
    print
'</code><pre><hr />';
?>
</section>

<h1>[2] Example `drop table` DBX structure</h1>
<section>

<?php
// perform queries
$dbx::query('d', $table_1, $fields_1);

?>

<?php
   
// print structure
   
print '<h2>DBX STRUCTURE</h2>';
    print
'<pre><code>';
   
print_r( $fields_1 );
    print
'</code></pre>';

   
// print result
   
print '<h2>DBX QUERY RESULT</h2>';
    print
'<pre><code>';
   
print_r( $dbx::$result );
    print
'</code><pre><hr />';

   
$dbx::query('c', $table_1, $fields_1);
?>
</section>

<h1>[3] Example `insert in table` DBX structure</h1>
<section>

<?php

// fields values for table_1 example
$fields_2 = [
   
'field_id' => [
       
'value' => 456
   
],
   
'field_text' => [
       
'value' => 'I have to add into my table'
   
],
   
'field_date' => [
       
'value' => date('Y-m-d')
    ]
];

// perform queries
$dbx::query('i', $table_1, $fields_2);

?>

<?php
   
// print structure
   
print '<h2>DBX STRUCTURE</h2>';
    print
'<pre><code>';
   
print_r( $fields_2 );
    print
'</code></pre>';

   
// print result
   
print '<h2>DBX QUERY RESULT</h2>';
    print
'<pre><code>';
   
print_r( $dbx::$result );
    print
'</code><pre><hr />';

?>

</section>

<h1>[3-1] Example `inject [auto UPDATE or INSERT] in table` DBX structure </h1>

<p>Simple provide an AUTO INCREMENT field value of 0 to perform INSERT query. If AUTO INCREMENT field value are exists will be performed UPDATE query.</p>

<section>

<?php

// fields values for table_1 example
$fields_2 = [
   
'field_id' => [
       
'value' => 0
   
],
   
'field_text' => [
       
'value' => 'Yo if field_id = 0 it\'s an insert or if id exists it\'s an update'
   
],
   
'field_date' => [
       
'value' => date('Y-m-d')
    ]
];

// perform queries
$dbx::query('in', $table_1, $fields_2);

?>


<?php
   
// print structure
   
print '<h2>DBX STRUCTURE</h2>';
    print
'<pre><code>';
   
print_r( $fields_2 );
    print
'</code></pre>';

   
// print result
   
print '<h2>DBX QUERY RESULT</h2>';
    print
'<pre><code>';
   
print_r( $dbx::$result );
    print
'</code><pre><hr />';

?>
</section>


<h1>[4] Example `update in table` DBX structure</h1>
<section>

<?php

// fields values for table_1 example
$fields_3 = [
   
'field_id' => [
       
'value' => 456
   
],
   
'field_text' => [
       
       
'new_value' => 'I was updated',

       
'criterion_field' => 'field_id',
       
'criterion_value' => 456

   
],
   
'field_date' => [
       
'value' => date('Y-m-d')
    ]
];

// perform queries
$dbx::query('u', $table_1, $fields_3);

?>

<?php
   
// print structure
   
print '<h2>DBX STRUCTURE</h2>';
    print
'<pre><code>';
   
print_r( $fields_3 );
    print
'</code></pre>';

   
// print result
   
print '<h2>DBX QUERY RESULT</h2>';
    print
'<pre><code>';
   
print_r( $dbx::$result );
    print
'</code><pre><hr />';

?>
</section>

<h1>[5] Example `select in table` DBX structure</h1>
<section>

<?php

// perform queries
$dbx::query('s|field_id|asc|100|0', $table_1, $fields_1);

?>

<?php
   
// print structure
   
print '<h2>DBX STRUCTURE</h2>';
    print
'<pre><code>';
   
print_r( $fields_1 );
    print
'</code></pre>';

   
// print result
   
print '<h2>DBX QUERY RESULT</h2>';
    print
'<pre><code>';
   
print_r( $dbx::$result );
    print
'</code><pre><hr />';

?>
</section>

<h1>[6] Example `delete from table` DBX structure</h1>
<section>

<?php

// fields values for table_1 example
$fields_3 = [
   
'field_id' => [
       
'value' => 456
   
]
];

// perform queries
$dbx::query('xd', $table_1, $fields_3);

?>

<?php
   
// print structure
   
print '<h2>DBX STRUCTURE</h2>';
    print
'<pre><code>';
   
print_r( $fields_3 );
    print
'</code></pre>';

?>
</section>

<h1>[7] Example `truncate from table` DBX structure</h1>
<section>

<?php

// perform queries
$dbx::query('t', $table_1, $fields_3);
$dbx::query('d', $table_1, $fields_3);

?>

<?php
   
// print structure
   
print '<h2>DBX STRUCTURE</h2>';
    print
'<pre><code>';
   
print_r( $fields_3 );
    print
'</code></pre><hr />';
?>
</section>

<h1>[8] Example `drop from table` DBX structure</h1>
<section>
<?php

// perform queries
$dbx::query('d', $table_1, $fields_3);

?>

<?php
   
// print structure
   
print '<h2>DBX STRUCTURE</h2>';
    print
'<pre><code>';
   
print_r( $fields_3 );
    print
'</code></pre><hr />';
?>
</section>

    </main>

</body>
</html>