参照:
https://packagist.org/packages/catfan/medoo
php关于数据库操作的工具类有很多, 现在介绍一种兼容性较好,比较简单,上手容易的sql类,Medoo。
对于一些小项目来说完全够用。
使用Medoo类对环境的要求:
- PHP >=5.4 with PDO supported.
- Installed SQL database like MySQL, MSSQL, SQLite or others.
- Make sure php_pdo_xxx extension is correctly installed and enabled.
- A little bit SQL knowledge.
安装:
composer require catfan/medoo
初步使用:
// If you installed via composer, just use this code to require autoloader on the top of your projects. require 'vendor/autoload.php'; // Using Medoo namespace use Medoo\Medoo; // Initialize $database = new Medoo([ 'database_type' => 'mysql', 'database_name' => 'name', 'server' => 'localhost', 'username' => 'your_username', 'password' => 'your_password' ]); // Enjoy $database->insert('account', [ 'user_name' => 'foo', 'email' => '[email protected]' ]); $data = $database->select('account', [ 'user_name', 'email' ], [ 'user_id' => 50 ]); echo json_encode($data);