Medoo Introduction
Medoo is a lightweight php SQL database framework developed by Li yanzhuo, a social networking website Catfan and founder of Qatrix, an open-source project. It provides simple, easy to learn, and flexible APIs to improve the efficiency and performance of Web application development, and the size is less than 8 KB.
Features
Lightweight, with only one file
Easy to learn and clear Data Structure
Supports multiple SQL syntaxes and complex query conditions.
Supports a variety of databases, including MySQL, MSSQL, SQLite, etc.
Secure and prevents SQL Injection
Free, based on the MIT Protocol
Sample Code
Add
Copy codeThe Code is as follows:
$ Database = new medoo ("my_database ");
$ Last_user_id = $ database-> insert ("account ",[
"User_name" => "foo ",
"Email" => "foo@bar.com ",
"Age" => 25,
"Lang" => [
"En ",
"Fr ",
"Jp ",
"Cn"
]
]);
Delete
Copy codeThe Code is as follows:
$ Database = new medoo ("my_database ");
$ Database-> delete ("account ",[
"AND" => [
"Type" => "business"
"Age [<]" => 18
]
]);
Modify
Copy codeThe Code is as follows:
$ Database = new medoo ("my_database ");
$ Database-> update ("account ",[
"Type" => "user ",
// All age plus one
"Age [+]" => 1,
// All level subtract 5
"Level [-]" => 5,
"Lang" => [
"En ",
"Fr ",
"Jp ",
"Cn ",
"De"
]
], [
"User_id [<>" => 1000
]);
Query
Copy codeThe Code is as follows:
$ Database = new medoo ("my_database ");
$ Datas = $ database-> select ("account ",[
"User_name ",
"Email"
], [
"User_id [& gt;]" = & gt; 100
]);
// $ Datas = array (
// [0] => array (
// "User_name" => "foo ",
// "Email" => "foo@bar.com"
//),
// [1] => array (
// "User_name" => "cat ",
// "Email" => "cat@dog.com"
//)
//)
Foreach ($ datas as $ data ){
Echo "user_name:". $ data ["user_name"]. "-email:". $ data ["email"]. "<br> ";
}
// Select all columns
$ Datas = $ database-> select ("account ","*");
// Select a column
$ Datas = $ database-> select ("account", "user_name ");
// $ Datas = array (
// [0] => "foo ",
// [1] => "cat"
//)