Home  >  Article  >  Backend Development  >  PHP lightweight database operation class Medoo add, delete, modify, query examples_PHP tutorial

PHP lightweight database operation class Medoo add, delete, modify, query examples_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:26:32873browse

Introduction to Medoo

Medoo is an ultra-lightweight PHP SQL database framework developed by Li Yanzhuo, the founder of the social networking site Catfan and the open source project Qatrix. It provides a simple, easy-to-learn, and flexible API to improve the efficiency and performance of developing web applications, and the size is less than 8KB.

Features

Lightweight, only one file

Easy to learn, the data structure is clear at a glance

Supports multiple SQL syntaxes and complex query conditions

Supports multiple databases, including MySQL, MSSQL, SQLite, etc.

Secure to prevent SQL injection

Free, based on MIT license

Sample code

Added

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

$database = new medoo ( "my_database" );
     
$database->delete("account", [
"AND" => [
"type" => "business"
"age[<]" => 18
]
]);

Modify

Copy code The 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 code The code is 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"] . "
";
}

// Select all columns
$datas = $database->select ( "account", "*" );

// Select a column
$datas = $database->select ( "account", "user_name" );
     
// $datas = array(
// [0] => "foo",
// [1] => "cat"
// )

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/824650.htmlTechArticleMedoo introduction Medoo is an ultra-lightweight PHP SQL database framework developed by the social networking site Catfan and the open source project Qatrix Developed by founder Li Yanzhuo. Provides a simple, easy-to-learn, flexible API, providing...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn