PHP code example of hxgf / dbkit

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

    

hxgf / dbkit example snippets


use VPHP\db;

$GLOBALS['database'] = db::init([
  'host' => 'localhost',
  'name' => 'database_name',
  'user' => 'username',
  'password' => 'password',
  'driver' => 'mysql', // optional, defaults to 'mysql'
  'port' => '3306', // optional, defaults to '3306'
  'charset' => 'utf8mb4', // optional, defaults to 'utf8mb4'
]);

$new_id = db::insert("celestial_bodies", [
  'name' => 'Luna',
  'classification' => 'moon',
  'comment' => 'Earth\'s moon, also commonly referred to as "the moon"'
]);

echo $new_id;

$planets = db::find("celestial_bodies", "classification = 'planet' ORDER BY title ASC LIMIT 8");

foreach ($planets['data'] as $p){
  echo $p['title'];
  echo $p['classification'];
  // etc, etc
}

echo $planets['total'];  // 8

$space_objects = db::find("", "SELECT title, classification FROM celestial_bodies WHERE id IS NOT NULL", [
  'raw' => true
]);

db::update("celestial_bodies", [
  'name' => 'Mars',
  'comment' => 'Research "The Phobos Incident" -- we are not alone'
], "name='Marz'");

db::delete("celestial_bodies", "name='venice'");

$wd = db::create_placeholders($where);
try {
  $query = "SELECT * FROM $table WHERE " . $wd['where'];
  $a = $GLOBALS['database']->prepare($query);
  $a->execute($wd['data']);
  $a->setFetchMode(PDO::FETCH_ASSOC);
}
catch(PDOException $e) {
  echo $e->getMessage();
}

$GLOBALS['database']->exec('CREATE TABLE users (
			id INT(255) NOT NULL AUTO_INCREMENT,
			password VARCHAR(255) NULL DEFAULT NULL,
			email VARCHAR(255) NULL DEFAULT NULL,
			PRIMARY KEY (id)
			) ENGINE=InnoDB CHARACTER SET utf8;');

$GLOBALS['database']->query('DESCRIBE users')->fetchAll(PDO::FETCH_ASSOC)