Example of adding, deleting, modifying, and querying PHP lightweight database operations

Source: Internet
Author: User

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"
//)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.