File: README.md

Recommend this page to a friend!
  Classes of Arash Soleimani  >  LMSQL  >  README.md  >  Download  
File: README.md
Role: Documentation
Content type: text/markdown
Description: Documentation
Class: LMSQL
Connect and perform MySQL database queries
Author: By
Last change: update Readme
Date: 2 months ago
Size: 2,591 bytes
 

Contents

Class file image Download

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 `php $data = $mysql->select(['table'=>'news']); `
  • With fields, where clause, order and limit. `php $data = $mysql->select([ 'table'=>'tableName', 'fields'=>'id, title, body', 'where'=>['category'=>'news'], 'order'=>'id DESC', 'limit'=>10 ]); `
  • With custom array index `php $data = $mysql->select([ 'table'=>'tableName', 'index'=>['column'=>'type', 'multi'=>true] ]); `
  • With custom SQL `php $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);

For more information send a message to info at phpclasses dot org.