最後更新: 2017-03-14
介紹
Homepage: http://medoo.in/
支持: MySQL, MSSQL, SQLite, MariaDB, Oracle, Sybase, PostgreSQL and more.
requiring: php_pdo extension list
- MySQL, MariaDB -> php_pdo_mysql
Centos 安裝:
yum install php-pdo
extension=php_pdo_mysql.dll
Usage:
// Include Medoo (configured) require_once 'medoo.php'; // initialize via independent configuration $db = new medoo([ 'database_type' => 'mysql', 'database_name' => 'name', 'server' => 'localhost', 'username' => 'your_username', 'password' => 'your_password', ]);
Testing:
print_r($db->info());
Array ( [server] => Uptime: 8390794 Threads: 1 Questions: 9276842 Slow queries: 0 Opens: 18888 Flush tables: 1 Open tables: 64 Queries per second avg: 1.105 [driver] => mysql [client] => 5.1.69 [version] => 5.1.69 [connection] => Localhost via UNIX socket )
Test some function:
// Enjoy $database->insert('account', [ 'user_name' => 'foo' 'email' => '[email protected]', 'age' => 25, 'lang' => ['en', 'fr', 'jp', 'cn'] ]);
Multi-insertion
=========
$last_user_id = $database->insert("account", [
[
"user_name" => "foo",
"email" => "[email protected]",
"age" => 25,
"city" => "New York",
"(JSON) lang" => ["en", "fr", "jp", "cn"]
],
[
"user_name" => "bar",
"email" => "[email protected]",
"age" => 14,
"city" => "Hong Kong",
"(JSON) lang" => ["en", "jp", "cn"]
]);
Using SQL functions
============
$last_user_id = $database->insert("account", [
"user_name" => "bar",
"#uid" => "UUID()"
]);
$data = $database->select('account', [
'user_id',
'user_name'
], [
'#datetime' => 'NOW()'
]);
Select
====
select($table, $columns, $where)
$datas = $database->select("account", ["user_name","email"], ["user_id[>]" => 100]);
* Return: [array]
* use "*" as columns parameter to fetch all columns
foreach($datas as $data)
{
echo "user_name:" . $data["user_name"] . " - email:" . $data["email"] . "<br/>";
}
$database->select("account", "user_name", [
"email" => "[email protected]"
]);
// WHERE email = '[email protected]'
$database->select("account", "user_name", [
"user_id" => 200
]);
// WHERE user_id = 200
$database->select("account", "user_name", [
"user_id[>]" => 200
]);
// WHERE user_id > 200
$database->select("account", "user_name", [
"user_id[>=]" => 200
]);
// WHERE user_id >= 200
$database->select("account", "user_name", [
"user_id[!]" => 200
]);
// WHERE user_id != 200
$database->select("account", "user_name", [
"age[<>]" => [200, 500]
]);
// WHERE age BETWEEN 200 AND 500
$database->select("account", "user_name", [
"age[><]" => [200, 500]
]);
// WHERE age NOT BETWEEN 200 AND 500
// [Compound]
$database->has("account", [
"AND" => [
"OR" => [
"user_name" => "foo",
"email" => "[email protected]"
],
"password" => "12345"
]
]);
// WHERE (user_name = 'foo' OR email = '[email protected]') AND password = '12345'
// Multi-order
$database->select("account", "user_id", [
"ORDER" => ['user_name DESC', 'user_id ASC']
]);
count
====
count($table, $where)
max
===
max($table, $column, $where)
PHP Persistent Database Connections
PHP as a CGI "wrapper"
When run this way, an instance of the PHP interpreter is created and destroyed for every page request (for a PHP page) to your web server. Because it is destroyed after every request, any resources that it acquires (such as a link to an SQL database server) are closed when it is destroyed. In this case, you do not gain anything from trying to use persistent connections -- they simply don't persist.
Run PHP as a module
in a multiprocess web server, which currently only includes Apache. A multiprocess server typically has one process (the parent) which coordinates a set of processes (its children) who actually do the work of serving up web pages.
When a request comes in from a client, it is handed off to one of the children that is not already serving another client. This means that when the "same client" makes a second request to the server, it may be served by a "different child process" than the first time.
When opening a persistent connection, every following page requesting SQL services can reuse the same established connection to the SQL server.
PHP as a plug-in (WSAPI)
same as for the multiprocess model described before.
DOC
http://medoo.in/doc
附加檔案 | 大小 |
---|---|
medoo_0.9.6.2.7z | 3.82 KB |