PHP Database wrapper: Medoo

June 10, 2014 in PHP


NOTE: I no longer use Medoo, or PHP for this site

So the other day (When I was completely rewriting this site), I was looking for a better way to deal with my databases. Particularly, a more secure and easy way to retrieve data from my databases. During my scouring of the Internet, I came across Medoo. Medoo is a simple php database framework that makes is really easy to run queries. It has a different syntax than a normal query (because it builds it within), but its pretty easy to get a hang of.

The basis behind it is that its object oriented. To use is, you need to instantiate it, and then you can run the different functions on it to get your results. Here's a quick example of a select statement (In fact, the one that I *used to* use to generate the Coding category menu :P).

   
$medoo = new Medoo();   
$coding_posts = $medoo->select("posts", "*", array(     
    "ORDER" => "id DESC",       
    "category_id" => 4)
);

Pretty slick, huh?

Here's how it all works, the first statement is the table that I'm looking at, in this case, "posts." Second, are the columns that I want to retrieve. (* indicates all of them). And third, is an array of arguments, In this case an order, and a restraint to get the posts in the Coding category

The project is still under development on Github and new features are being added all the time. They also have a ton of great documentation on their website which can tell you tons more about the different functions that you can run.

While its not fully featured yet, this is a great tool for starters. Its easy to use, and secure against injection (because it uses prepared statements). Once every SQL function is implemented, it will be a great PHP tool