PHP Lightweight Database Operations Class Medoo Add, delete, modify, query examples _php examples

Source: Internet
Author: User
Tags sql injection

Medoo Introduction

Medoo is a lightweight PHP SQL database framework developed by the founder Li Yan of the social networking site Catfan and the Open-source project Qatrix. Provides a simple, easy to learn, flexible API to enhance the efficiency and performance of Web application development, and the volume is only 8KB.

Characteristics

Lightweight, only one file

Simple and easy to learn, data structure at a glance

supports a variety of SQL syntax and supports complex query conditions

supports a variety of databases, including MySQL, MSSQL, SQLite, etc.

Security to prevent SQL injection

Free, based on the MIT Protocol

Sample code

Increase

Copy Code code 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 Code code as follows:

$database = new Medoo ("My_database");

$database->delete ("Account", [
"and" => [
"Type" => "Business"
"AGE[<]" => 18
]
]);

Modify

Copy Code code 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
] );

Inquire

Copy Code code as follows:

$database = new Medoo ("My_database");

$datas = $database->select ("Account", [
"User_name",
"Email"
], [
"USER_ID[>]" => 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.