推荐一个php的mysql操作类medoo

 之前一直用的不好使,最近发现了这个玩意,感觉还可以,推荐一下:http://medoo.in/

支持操作:

MySQL, MariaDB -> php_pdo_mysql
MSSQL (Windows) -> php_pdo_sqlsrv
MSSQL (Linux/UNIX) -> php_pdo_dblib
Oracle -> php_pdo_oci
SQLite -> php_pdo_sqlite
PostgreSQL -> php_pdo_pgsql
Sybase -> php_pdo_dblib

基本操作示例:更多教程 http://medoo.in/doc

require ‘medoo.php’;  //引入文件
// 创建数据库连接对象 应该不用解释都看得懂
$database = new medoo([
// required
‘database_type’ => ‘mysql’,
‘database_name’ => ‘name’,
‘server’ => ‘localhost’,
‘username’ => ‘your_username’,
‘password’ => ‘your_password’,
‘charset’ => ‘utf8’,

// [optional]
‘port’ => 3306,

// [optional] Table prefix
‘prefix’ => ‘PREFIX_’,

// [optional] driver_option for connection, read more from 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"
]);

//更新数据

database->update("account", [
"type" => "user",

// All age plus one
"age[+]" => 1,

// All level subtract 5
"level[-]" => 5,

// All score multiplied by 2
"score[*]" => 2,

// Like insert, you can assign the serialization
"lang" => ["en", "fr", "jp", "cn", "de"],

"(JSON) fav_lang" => ["en", "fr", "jp", "cn", "de"],

// You can also assign # for using SQL functions
"#uid" => "UUID()"
], [
"user_id[<]" => 1000
]);

//查询数据

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

//删除数据

$database->delete("account", [
"AND" => [
"type" => "business",
"age[<]" => 18
]
]);

 

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注