Skip to content

leomoon-studios/LMSQL

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LMSQL

LMSQL is a simple MySQL class that uses PDO. With LMSQL you don't need to write a lot of code to get results from a table and it's very easy to use.

Documentation

Installation

require_once('mysql.class.php');

Commands

Connect

$mysql = new LMSQL('localhost', 'root', '123456', 'databaseName', true);

or

$mysql = new LMSQL('localhost', 'root', '123456', 'databaseName');

$mysql->connect();

default charset is utf8.

select

Get data from table with where clause, limit, order and custom index

@return array

  • Simple usage
$data = $mysql->select(['table'=>'news']);
  • With fields, where clause, order and limit.
$data = $mysql->select([
                        'table'=>'tableName', 
                        'fields'=>'id, title, body', 
                        'where'=>['category'=>'news'], 
                        'order'=>'id DESC', 
                        'limit'=>10
                        ]);
  • With custom array index
$data = $mysql->select([
                      'table'=>'tableName', 
                      'index'=>['column'=>'type', 'multi'=>true]
                      ]);
  • With custom SQL
$data = $mysql->select(["sql"=>"SELECT news_title FROM news, category WHERE news_category = category_id and category_type = 'active'"]);

load

Get one row from table

@return array

$data = $mysql->load(['table'=>'news', 'where'=>'id = 1']);

insert

Insert data to table

$mysql->insert(['table'=>'users', 'values'=>['fullname'=>'Arash', 'company'=>'Leomoon']]);

update

Update rows

$mysql->update(['table'=>'users', 'where'=>['id'=>2218], 'values'=>['name'=>'Amin']]);

delete

Delete rows

$mysql->delete(['table'=>'tableName', 'where'=>['id', '817']]);

total

Get total rows

@return int

$mysql->total(['table'=>'tableName', 'where'=>'id > 5']);

or

$mysql->count(['table'=>'tableName', 'where'=>['status'=>'active', 'category'=>'something']]);

insertId

Get the last inserted id

$mysql->insertId();

search

Search in all fields

$mysql->search([
        'table'=>'news',
        'word'=>'%fake%'
    ]);

Search in specific fields

$mysql->search([
        'table'=>'news',
        'word'=>'%fake%',
        'searchs'=>['title']
    ]);

schema

Show tables of current DB:

$mysql->schema();

Show columns:

$mysql->schema(['table'=>'YourTableName']);

exec

Execute your custom sql query

$mysql->exec($sql);

About

Simplest MySQL class in the world

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages