Medoo: An Ideal Database Framework for Efficient Web Development

  • Cubettech
  • Web App Development
  • 9 years ago

Medoo is a light-weighted non-MVC framework that acts as an efficient medium to connect database to PHP. The framework was developed by Angel Lai, a profound designer and entrepreneur. Medoo is literally build using PHP and is compatible with MySQL, PostgreSQL, MSSQL, SQLite etc. It provides the facility to extend the existing functionality.

Installation

  • ·Download Medoo
  • ·There is only one file and you can configure it

protected $database_type = 'mysql'; protected $server = 'hostname'; protected $database_type = 'mysql'; protected $username = 'username'; protected $password = 'password';

Using Medoo in your projects

1.   Include medoo in your project

require_once 'medoo.php';

2.  Initialization

 $database = new medoo('database');

Coding

info() :

returns functions of database

Insertion :

$database->insert ('student', [ 'user_name' => 'abc' 'email' => ‘abc@gmail.com', 'age' => 25, ]);

Inserting values into the table student

Select :

$datas = $database->select ("student", [ "user_name", "email" ], ["user_id[>]" => 100 ]); foreach($datas as $data) { echo "user_name:" . $data["user_name"] . “- email:”. $data["email"] . "<br/>"; }

select user_name , email , user_id from table student with user_id > 100
and display the data using for loop

Update :

$database->update(“student”,[“email”=>”abc@gmail.com”],[“user_id”=>”2”]); update the table row student with email is  abc@gmail.com and user_id is 2

Delete :

$database->delete(“student”,[“AND”=>[“user_id”=>”3”]]);

delete the row from the table student with user_id is 3

Aggregate functions:

count/min/max/avg/sum

Given below is an example of aggregate function for finding minimum age.

$database->min(“student”, “age”,[“age[<]”=>”20”]);

returns the min of age from the table student with age less than 20.

Replace:

replace the old data into new one.

$database->replace("student", ["type" => [ "user" => "new_user"],"group" => ["groupA" => "groupB"]], ["user_id[>]" => 1000]);

Medoo is simple and handy; it has method for all the SQL queries. It does not cause any revolutionary change but for free MIT license, you can use it anywhere you want. I’m definitely planning to write more about Medoo, i would love to hear your opinions about this post, therefore, don’t hesitate to drop a comment.

Know More About This Topic from our Techies

Table of Contents

    Contact Us

    Contact

    What's on your mind? Tell us what you're looking for and we'll connect you to the right people.

    Let's discuss your project.

    Phone