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" => "[email protected]",
"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" => "[email protected]"
// ),
// [1] => array(
// "user_name" => "cat",
// "email" => "[email protected]"
// )
// )
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"
// )