PHP Classes

File: README-GR.md

Recommend this page to a friend!
  Classes of Christos Drogidis   jsqldb   README-GR.md   Download  
File: README-GR.md
Role: Documentation
Content type: text/markdown
Description: Greek Readme
Class: jsqldb
Examples to use JSQLDB to store data in JSON files
Author: By
Last change: Greek Readme
Date: 8 months ago
Size: 5,485 bytes
 

Contents

Class file image Download

JSQLDB - JSON SQL Database for PHP

? ??? ???????, SQL-like ???? ????????? ????????? ?? JSON ??? PHP

?? JSQLDB ????? ??? ???????? ??????? ????? ????????? ??? ????????? JSON ??? ?????????? ??? ??????? SQL-like queries ????? ??? ?????? ??? SQLite ? MySQL. ????? ??????, ??????? ??? ??????? ??? ????????? ??? ??????????? ?????????? ??? ????????.

JSQL Database

? ??????????????

  • ? JSON-based ?????????? ????? DLL/SO ??????????
  • ? SQL-like queries ?? ?????????? `SELECT`, `INSERT`, `UPDATE`, `DELETE`, `JOIN`, `UNION`, `GROUP - BY`, `HAVING`, `LIMIT`, `ORDER BY`, `DISTINCT` ???.
  • ? ?????????? Indexing ??? ??????? ?????????
  • ? ??????????? ?????????? ??? ???????????????? ????? ?????
  • ? ?????????? ????????? ??????????? ??? ?????? ?????????? ?????????
  • ? ???????????????? ??? PHP 8.2+

? ???????:

  • PHP 8.2+
  • Ascoos Framework (??? ???????? ?????? ???????? ??? ??????????)
  • ionCube loaders.

? ???????????

git clone https://github.com/alexsoft-software/jsql.git
cd jsql
composer install

?? ???????????? ???????????? ????????, ???? ??????????!

? ????? ??? ????? ?????????

??? ???? ????????? ?????? ?? ??? ??????????????? ???? ??? ????????????????. ???? ??????? ???? ??? ?????? ?????????.

? ?????????? ?????????


return [
    'jsql' => [
        'config_path' => '/root/path/conf/config.json', 
        'users_path' => '/root/path/conf/users.json',
        'databases_root_path' => '/root/path/jsql_db',      
    ]
];

? ?????????? ??????

use ASCOOS\FRAMEWORK\Kernel\DB\JSQLDB;

// ?????????? ??? ??? ?????? ????????? ??? ??????????? ??????????? ??? ????? ?????????. 
$conf = require "conf/config.php";

$properties['tables_prefix'] = 'ascoos'; // ?? ????? ?.?. ???? ?????? "ascoos_articles'

// ???????????? ??? ???????????? ??? ????? ?????????
$jsql = new TJSQLDB($conf, $properties);

// ?????????? ????? ?????????
$jsql->createDatabase('test_db');

// ?????????? ?????? ??? ???????????? ?? ???? ?????????
$jsql->createUser('admin', 'root', 'test_db');

// ??????? ????????? ????? ?????????
$jsql->select_db('test_db');

// ?????????? ??????
$sql = "CREATE TABLE `#__articles` (
  `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
  `article_id` INT UNSIGNED NOT NULL DEFAULT 0,
  `cat_id` INT UNSIGNED NOT NULL DEFAULT 0,
  `user_id` INT UNSIGNED NOT NULL DEFAULT 0,
  `lang_id` INT UNSIGNED NOT NULL DEFAULT 0,
  `title` VARCHAR(200) NOT NULL,
  `content` TEXT NULL COMPRESSED,
  `created` DATETIME NULL DEFAULT CURRENT_TIMESTAMP(),
  `updated` DATETIME NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP()
);";

$jsql->setSQLQuery($sql);
$jsql->execute();

// ???????? ?????????
$query->setSQLQuery("INSERT INTO #__articles (article_id, cat_id, user_id, lang_id, title, content) VALUES 
(1, 1, 1, 1, 'Title 1', 'Test Content 1'),
(1, 1, 1, 2, 'Title 2', 'Test Content 2'),
(2, 2, 1, 1, 'Title 3', 'Test Content 3'),
(3, 3, 1, 1, 'Title 4', 'Test Content 4'),
(3, 3, 1, 2, 'Title 5', 'Test Content 5');
");
$query->execute();

$query = "SELECT article_id AS aid, title, content AS doc FROM #__articles WHERE user_id = ".$my->id." AND lang_id = 1 ORDER BY created DESC LIMIT 10";
$jsql->setSQLQuery($query);
$jsql->execute();
$data = $jsql->getResults();

// ???????? ???? ??? ???????? ????? ??? ????? ?????????
$jsql->close();

print_r($data);
?>

? ???????????? ?????? ??????????? ??????


// ?????? ?????? ??????????? ?????? ??? ??? ????? ???.
$schema = [
  'id' => 'INT NOT NULL AUTO_INCREMENT PRIMARY KEY',
  'article_id' => 'INT UNSIGNED NOT NULL DEFAULT 0',
  'cat_id' => 'INT UNSIGNED NOT NULL DEFAULT 0',
  'user_id' => 'INT UNSIGNED NOT NULL DEFAULT 0',
  'lang_id' => 'INT UNSIGNED NOT NULL DEFAULT 0',
  'title' => 'VARCHAR(200) NOT NULL',
  'content' => ' TEXT NULL COMPRESSED',
  'created' => ' DATETIME NULL DEFAULT CURRENT_TIMESTAMP()',
  'updated' => 'DATETIME NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP()'
];
$jsql->createTable('#__articles', $schema);

? ????? ??????????? ???????????? ???? ??????? ??????????!