Medoo介紹
Medoo是一款超輕量級的PHP SQL資料庫架構,由社交網站Catfan和開源項目Qatrix的創始人黎言卓開發。提供了簡單,易學,靈活的API,提升開發Web應用的效率與效能,而且體積只有8KB不到。
特性
輕量級,只有一個檔案
簡單易學,資料結構一目瞭然
支援多種SQL文法,以及支援複雜的查詢條件
支援多種資料庫,包括MySQL, MSSQL, SQLite等等
安全,可防止SQL注入
免費,基於MIT協議
範例程式碼
增加
複製代碼 代碼如下:
$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"
]
] );
刪除
複製代碼 代碼如下:
$database = new medoo ( "my_database" );
$database->delete("account", [
"AND" => [
"type" => "business"
"age[<]" => 18
]
]);
修改
複製代碼 代碼如下:
$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
] );
查詢
複製代碼 代碼如下:
$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"
// )