What is Medoo? The Lightest PHP database framework to accelerate development! The lightest PHP database framework to accelerate development! Medoo's powerful and complete API can not only fully meet your most common and basic needs, but is also very simple to use. Even if secondary development is required, it will not be a problem at all. The first thing to translate is the introductory chapter of Medoo. First, let’s talk about the installation and configuration of Medoo.
What is Medoo? Let’s see what the official says:
The Lightest PHP database framework to accelerate development! //译: 加速开发的最轻量的PHP数据库框架!
Medoo’s slogan is still very loud, but is it actually useful? After using it for a period of time, I found that Medoo is really just like the official introduction, it can greatly speed up the development of your PHP project. When doing web development, a large number of companies or individuals will choose to use the PHP language, and Medoo can play an icing on the cake. Shorten your development cycle. Medoo's powerful and complete API can not only fully meet your most common and basic needs, but is also very simple to use. Even if secondary development is required, it will not be a problem at all. Despite this, the Chinese documentation on the Internet is still not perfect. Therefore, I decided to translate and organize Medoo myself. It may not be very accurate, but I still want to make it as easy to understand as possible without missing the official meaning. So, let’s start with the introductory chapter.
Getting Started
Using Medoo is that easy!
Requirements
Required PHP 5.1 or above, very, special, extremely, highly recommended: use PHP 5.4 or above and enable PDO support. You can install databases such as MySQL, MSSQL, SQLite, or more. Make sure the php_pdo_xxx (XXX = database name you want to use) extension is installed and enabled in php.ini. I think you may need a little basic knowledge of SQL. (As a developer, I think this is not a problem ^^!)
Warm reminder
About PHP 5.4+, you can use [] as the abbreviation syntax for arrays. All Medoo sample code uses [] instead of array() .
// PHP 5.1 中 var data = array("foo", "bar"); // PHP 5.4+ 中 var data = ["foo", "bar"];
Installation
Just download medoo.php and put it in the correct directory, and you’re good to go!
Configuration
There are two ways to configure medoo and start a database connection.
// 1. 独立配置的方法 require 'medoo.php'; $database = new medoo([ // required 'database_type' => 'mysql', 'database_name' => 'name', 'server' => 'localhost', 'username' => 'your_username', 'password' => 'your_password', //可选 'port' => 3306, 'charset' => 'utf8', // DB连接驱动选项,了解更多 http://www.php.net/manual/en/pdo.setattribute.php 'option' => [ PDO::ATTR_CASE => PDO::CASE_NATURAL ]]); $database->insert("account", [ "user_name" => "foo", "email" => "foo@bar.com"]); // 2. 直接打开 medoo.php 并在文件的顶部编辑一些配置信息, // 然后你之后就无需再次进行配置而直接使用它。 // MySQL, MSSQL, PostgreSQL, Sybase 的类型名如下: // MySQL -> mysql// MSSQL -> mssql // PostgreSQL -> pgsql // Sybase -> sybase class medoo{ protected $database_type = 'mysql'; // DB的类型名 protected $server = 'localhost'; protected $username = 'your_username'; protected $password = 'your_password'; // 可选 protected $port = 3306; protected $charset = 'utf8'; .... } // OK, 现在一切就绪了! require_once 'medoo.php'; $database = new medoo('my_database'); $database->insert("account", [ "user_name" => "foo", "email" => "foo@bar.com"] );
For SQLite
For MSSQL If you want to use MSSQL through Medoo under the PHP platform, you need to install the pdo_sqlsrv PHP extension in the Windows environment, or install the pdo_dblib PHP extension in the Liunx/UNIX environment. The pdo_mssql extension has been deprecated and will be removed from PHP soon.
// 1. 尽管编辑 medoo.php 文件里的DB类型名 class medoo{ protected $database_type = 'sqlite'; // For SQLite [optional] protected $database_file = 'my/database/path/database.db'; .... } // OK, 现在一切就绪了! require_once 'medoo.php'; $database = new medoo('my/database/path/database.db'); // 2. 或者独立配置 $database = new medoo([ 'database_type' => 'sqlite', 'database_file' => 'my/database/path/database.db'] ); $database->insert("account", [ "user_name" => "foo", "email" => "foo@bar.com"] );
Installation of PDO driver in PHP
Medoo requires PHP’s PDO extension. If you have not installed it before, please follow the steps below.
// 打开PHP安装目录下的php.ini文件,找到以下这一行并把行首的分号 ';'去掉。其它类型数据库请分别对应移除。 // 移除 ';' 之前 ;extension=php_pdo_mysql.dll // 移除 ';' 之后 extension=php_pdo_mysql.dll // 然后保存并重启Apache服务器 // 如果安装成功的话,你就可以通过 phpinfo() 看到 PDO扩展相关信息。
OK, now I have finally finished the DB operation framework easily. Isn't it very simple? ^^!