PHP Classes

LMSQL: Connect and perform MySQL database queries

Recommend this page to a friend!
  Info   View files Documentation   View files View files (7)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 168 All time: 8,845 This week: 149Up
Version License PHP version Categories
lmsql 1.2MIT/X Consortium ...5PHP 5, Databases
Description 

Author

This class can connect and perform MySQL database queries.

It can connect to a MySQL database using the PDO extension.

The class can also perform common queries taking some parameters like:

- Get data from a table with a condition clause, limit, order and custom sorting by field
- Get one row from a table
- Insert data into a table
- Update table rows
- Delete table rows
- Get the total number of table rows
- Get the last inserted table identifier
- Search in all fields
- Search in specific fields
- Show tables of current database
- Show columns of a table
- Execute a custom SQL query

Picture of Arash Soleimani
  Performance   Level  
Name: Arash Soleimani <contact>
Classes: 4 packages by
Country: The Netherlands The Netherlands
Age: ???
All time rank: 286176 in The Netherlands The Netherlands
Week rank: 312 Up10 in The Netherlands The Netherlands Up
Innovation award
Innovation award
Nominee: 2x

Documentation

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);

  Files folder image Files  
File Role Description
Files folder image.github (1 directory)
Files folder imagedemo (2 files)
Accessible without login Plain text file LICENSE Lic. License text
Plain text file mysql.class.php Class Class source
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  .github  
File Role Description
Files folder imageISSUE_TEMPLATE (2 files)

  Files folder image Files  /  .github  /  ISSUE_TEMPLATE  
File Role Description
  Accessible without login Plain text file bug_report.md Data Auxiliary data
  Accessible without login Plain text file feature_request.md Data Auxiliary data

  Files folder image Files  /  demo  
File Role Description
  Accessible without login Plain text file insert.php Example insert example
  Accessible without login Plain text file update.php Example update example

 Version Control Unique User Downloads Download Rankings  
 100%
Total:168
This week:0
All time:8,845
This week:149Up