Medoo介绍
Medoo是一款超轻量级的PHP sql数据库框架,由社交网站Catfan和开源项目Qatrix的创始人黎言卓开发。提供了简单,易学,灵活的API,提升开发Web应用的效率与性能,而且体积只有8KB不到。
特性
轻量级,只有一个文件
简单易学,数据结构一目了然
支持多种数据库,包括MysqL,MSsql,sqlite等等
安全,可防止sql注入
免费,基于MIT协议
示例代码
增加
$last_user_id = $database->insert ( "account",[ "user_name" => "foo", "email" => "foo@bar.com", "age" => 25, "lang" => [ "en", "fr", "jp", "cn" ] ] );
删除
"AND" => [
"type" => "business"
"age[<]" => 18
]
]);
修改
$database->update ( "account",[ "type" => "user",
// All age plus one
"age[+]" => 1,
// All level subtract 5
"level[-]" => 5,
"lang" => [
"en",
"cn",
"de"
]
],[
"user_id[<]" => 1000
] );
查询
$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"
// )