Skip to content

LocalSQL: Bridging the Gap Between PHP and MySQL Coding Worries.

License

Notifications You must be signed in to change notification settings

Owens94819/MyLocalSQL

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

13 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

don't forget to give this repo a star 🌟

LocalSQL πŸ€–

LocalSQL example image

LocalSQL is a lightweight PHP framework designed to simplify database interactions with MySQL. It empowers PHP developers by reducing the need to struggle with complex MySQL syntax and offers a more secure coding experience πŸ‘·.

NOTE: LocalSQL also provides protection against SQL injections πŸ’‰ πŸ‘Ž πŸ’ͺ.

Installation πŸ’»

To get started with LocalSQL, simply download the localSQL.php file and import it into your project.

<?php
require_once("./localSQL.php");

Using LocalSQL πŸ“

LocalSQL is designed to be straightforward, with self-explanatory naming conventions 😎.

<?php
$localSQL = new LocalSQL("DB_HOST", "DB_USER", "DB_PASSWORD");

LocalSQL Class

The LocalSQL class is the core part of the LocalSQL framework, taking three parameters πŸ’£:

  • DB_HOST: Database host name
  • DB_USER: Database user name
  • DB_PASSWORD: Database user password

Here are the methods available when using the LocalSQL class πŸŽ†:

openDB

This method creates a database if the given name doesn't exist or opens it if it does.

<?php
$database = $localSQL->openDB("DB_name");

This method returns an instance of the Table class πŸ˜‰.

removeDB

Use this method to remove a specified database.

<?php
$result = $localSQL->removeDB("DB_name");

It returns TRUE or FALSE πŸ˜‡.

hasDB

Check if a specific database exists using this method.

<?php
$result = $localSQL->hasDB("DB_name");

This method returns TRUE or FALSE 😰.

keys

Retrieve a list of all available database names using this method.

<?php
$result = $localSQL->keys();

It returns an array list πŸ˜‰.

removeAllDB

Delete all available databases using this method.

<?php
$result = $localSQL->removeAllDB();

It returns TRUE or FALSE πŸ˜‡.

localStorage

Automatically open a database named "localStorage" and a table with the specified name.

<?php
$table = $localSQL->localStorage("TABLE_name");

This method returns an instance of the Item class πŸ˜‡.

Table Class

Here are the methods available when using the openDB method:

openTable

This method creates a database table if the given name doesn't exist or opens it if it does.

<?php
$table = $database->openTable("TABLE_name");

It returns an instance of the Item class πŸ˜‰.

removeTable

Remove a specified table using this method.

<?php
$result = $database->removeTable("TABLE_name");

This method returns TRUE or FALSE πŸ˜‡.

hasTable

Check if a specific table exists with this method.

<?php
$result = $database->hasTable("TABLE_name");

It returns TRUE or FALSE 😯.

keys

Retrieve a list of all available table names using this method.

<?php
$result = $database->keys();

It returns an array list 😱.

removeAllTable

Delete all available tables from the database using this method.

<?php
$result = $database->removeAllTable();

It returns TRUE or FALSE πŸ˜‡.

Item Class

When using the openTable method, you can access the following methods:

setItem

Create or set an item inside the database table using this method.

<?php
  $table->setItem("name", "value");

appendItem

Create or append(concat) an item to an existing item inside the database table using this method.

<?php
 $table->appendItem("name", "value to append");

A good use case could be with the file system

<?php
$file_handle = fopen("my_large_file.txt", "r");

while(!feof($file_handle)){
  $chunk = fread($file_handle, 1024);
  $table->appendItem("my file.txt", $chunk);
}

getItem

Retrieve an item from the database table using this method.

<?php
$item = $table->getItem("name");

This method returns the item value 😊.

getChunkItem

Retrieve a large item from the database table in chunks using this method.

this method takes two parameters, the name and callback.

  • callback the callback function is fired with two arguments, the value and a method
<?php
$table->getChunkItem("name", function($chunk, $continue){
  if($chunk){
  echo($chunk);
  $continue();
  }
});

A good use case could also be with the file system

<?php
$file_handle = fopen("large.txt", "w");

$table->getChunkItem("name", function ($chunk, $continue){
  global $file_handle;
  if($chunk){ 
    fwrite($file_handle, $chunk);
    $continue();
  }else{
    fclose($file_handle);
  }
}
);

hasItem

Check if a specific item exists in the table with this method.

<?php
$result = $table->hasItem("name");

It returns TRUE or FALSE 😻.

keys

Retrieve a list of all item names available in the table.

<?php
$result = $table->key();

It returns an array list πŸ˜‰.

removeItem

Remove a specific item from the table using this method.

<?php
$result = $table->removeItem("name");

It returns TRUE or FALSE πŸ‘Ό.

removeAllItem

Remove all available items from the table using this method.

<?php
$result = $table->removeAllItem();

This method returns TRUE or FALSE πŸ‘».

getAllItem

Retrieve all items from the database table using this method.

<?php
$items = $table->getAllItem();

This method returns an array object 🍻.

PHP Version Support 🌠

So far, this framework works on PHP version 7.1.33, and previous PHP versions are yet to be tested 🎠.

Conclusion πŸ“œ

LocalSQL is a PHP framework that simplifies the process of working with MySQL databases. By providing an intuitive and secure interface, it allows PHP developers to focus on their coding, rather than struggling with complex SQL syntax and worrying about security vulnerabilities.

With LocalSQL, you can easily create and manage databases, tables, and items with straightforward methods. It's a lightweight and user-friendly solution for database interaction, designed to make your development process smoother and more efficient.

We hope you find LocalSQL useful and that it enhances your PHP development experience. If you have any questions, feedback, or would like to collaborate, please don't hesitate to reach out to us on FacebookπŸ“±.

Kudos for choosing LocalSQL, and happy coding! πŸ‘·

About

LocalSQL: Bridging the Gap Between PHP and MySQL Coding Worries.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages