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.
require_once('mysql.class.php');
$mysql = new LMSQL('localhost', 'root', '123456', 'databaseName', true);
or
$mysql = new LMSQL('localhost', 'root', '123456', 'databaseName');
$mysql->connect();
default charset is utf8.
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'"]);
Get one row from table
@return array
$data = $mysql->load(['table'=>'news', 'where'=>'id = 1']);
Insert data to table
$mysql->insert(['table'=>'users', 'values'=>['fullname'=>'Arash', 'company'=>'Leomoon']]);
Update rows
$mysql->update(['table'=>'users', 'where'=>['id'=>2218], 'values'=>['name'=>'Amin']]);
Delete rows
$mysql->delete(['table'=>'tableName', 'where'=>['id', '817']]);
Get total rows
@return int
$mysql->total(['table'=>'tableName', 'where'=>'id > 5']);
or
$mysql->count(['table'=>'tableName', 'where'=>['status'=>'active', 'category'=>'something']]);
Get the last inserted id
$mysql->insertId();
Search in all fields
$mysql->search([
'table'=>'news',
'word'=>'%fake%'
]);
Search in specific fields
$mysql->search([
'table'=>'news',
'word'=>'%fake%',
'searchs'=>['title']
]);
Show tables of current DB:
$mysql->schema();
Show columns:
$mysql->schema(['table'=>'YourTableName']);
Execute your custom sql query
$mysql->exec($sql);