Medoo是什么呢?看看官方是怎么写的:
The Lightest PHP database framework to accelerate development!
Medoo的口号还是喊得很响的,实际上是否真的好用呢?经过一段时间的使用,我发现Medoo真的就像官方介绍的那样,可以极大地加快你的PHP项目的开发。在进行Web开发的时候,很大一部分企业或个人都会选择使用PHP语言,而Medoo则可以起到锦上添花的作用。缩短你的开发周期。Medoo强大而完善的API不仅完全可以满足你最常用最基本的需求,而且使用起来也非常简单。即使要进行二次开发,也丝毫不成问题。虽然如此,但是网上的中文文档还是不够完善。因此,我决定自己对Medoo进行翻译和整理。也许不能够非常准确,但是还是想在不遗漏官方传达的意思的基础上,尽量做到通俗易懂。那么,就从入门篇开始吧。
入门
使用Medoo就是这么简单!
需求
必须 PHP 5.1以上,非常、特别、极其、强烈推荐:使用PHP 5.4以上版本并开启PDO支持。 你可以安装MysqL,MSsql,sqlite等数据库,或者更多其它数据库。 确保 PHP_pdo_xxx(XXX = 你想要使用的数据库名)扩展在PHP.ini中被安装并启用。 我想你也许需要一点点的sql基本知识。(作为开发人员,我想这不成问题 ^^!)
温馨提示
关于PHP 5.4+中,你可以使用 [] 作为数组的缩写语法。所有Medoo示例代码都使用 [] 来替代 array() 。
安装
只要下载 medoo.PHP 并把它放到正确的目录,就一切OK了!
配置
$database
=
new
medoo([
// required
'database_type'
=>
'MysqL'
PHP plain" style="white-space:Nowrap; padding:0px!important; margin:0px!important; border:0px!important; bottom:auto!important; float:none!important; height:auto!important; left:auto!important; line-height:1.1em!important; outline:0px!important; overflow:visible!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-family:Consolas,
'database_name'
'name'
PHP plain" style="white-space:Nowrap; padding:0px!important; margin:0px!important; border:0px!important; bottom:auto!important; float:none!important; height:auto!important; left:auto!important; line-height:1.1em!important; outline:0px!important; overflow:visible!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-family:Consolas,
'server'
'localhost'
PHP plain" style="white-space:Nowrap; padding:0px!important; margin:0px!important; border:0px!important; bottom:auto!important; float:none!important; height:auto!important; left:auto!important; line-height:1.1em!important; outline:0px!important; overflow:visible!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-family:Consolas,
'username'
'your_username'
PHP plain" style="white-space:Nowrap; padding:0px!important; margin:0px!important; border:0px!important; bottom:auto!important; float:none!important; height:auto!important; left:auto!important; line-height:1.1em!important; outline:0px!important; overflow:visible!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-family:Consolas,
'password'
'your_password'
PHP plain" style="white-space:Nowrap; padding:0px!important; margin:0px!important; border:0px!important; bottom:auto!important; float:none!important; height:auto!important; left:auto!important; line-height:1.1em!important; outline:0px!important; overflow:visible!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-family:Consolas,
//可选
'port'
=> 3306,
'charset'
'utf8'
PHP plain" style="white-space:Nowrap; padding:0px!important; margin:0px!important; border:0px!important; bottom:auto!important; float:none!important; height:auto!important; left:auto!important; line-height:1.1em!important; outline:0px!important; overflow:visible!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-family:Consolas,
'option'
=> [
PDO::ATTR_CASE => PDO::CASE_NATURAL
]]);
$database
->insert(
"account"
PHP plain" style="white-space:Nowrap; padding:0px!important; margin:0px!important; border:0px!important; bottom:auto!important; float:none!important; height:auto!important; left:auto!important; line-height:1.1em!important; outline:0px!important; overflow:visible!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-family:Consolas, [
"user_name"
PHP plain" style="white-space:Nowrap; padding:0px!important; margin:0px!important; border:0px!important; bottom:auto!important; float:none!important; height:auto!important; left:auto!important; line-height:1.1em!important; outline:0px!important; overflow:visible!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-family:Consolas,
"email"
"foo@bar.com"
]);
// 然后你之后就无需再次进行配置而直接使用它。
// Sybase -> sybase
class
medoo{
protected
$database_type
=
;
// DB的类型名
$server
;
$username
;
$password
;
// 可选
$port
= 3306;
$charset
;
....
}
// OK, 现在一切就绪了!
require_once
;
medoo(
'my_database'
);
PHP variable" style="white-space:Nowrap; padding:0px!important; margin:0px!important; border:0px!important; bottom:auto!important; float:none!important; height:auto!important; left:auto!important; line-height:1.1em!important; outline:0px!important; overflow:visible!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-family:Consolas, [
PHP spaces" style="white-space:Nowrap; padding:0px!important; margin:0px!important; border:0px!important; bottom:auto!important; float:none!important; height:auto!important; left:auto!important; line-height:1.1em!important; outline:0px!important; overflow:visible!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-family:Consolas,
]
);