PHP輕量級資料庫操作類Medoo增加、刪除、修改、查詢例子_php執行個體

來源:互聯網
上載者:User

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"
    // )

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.