Medoo

开始

更新日志

Where 语句

查询

聚合

Fetch

事务

原生SQL查询

Raw object

PDO object

Debug

数据库信息

1.6

较1.5.7,新增加了Rand()方法

升级到1.4

Medoo由1.2之前的版本升级到1.4,会有一些不兼容的问题,这儿列举升级需要注意的一些事项

安装版本

Medoo1.2之前的版本支持php5.1,但1.2之后的仅支持php5.4及以上的版本

Medoo现在使用命名空间和PSR标准。所以必须在初始化之前使用Medoo\Medoo来声明命名空间,同时实例化的时候方法名将 new medoo() 更改为 new Medoo(),注意这个大小写

旧版本

require 'vendor/autoload.php';

$database = new medoo([
	'database_type' => 'mysql',
	'database_name' => 'name',
	'server' => 'localhost',
	'username' => 'your_username',
	'password' => 'your_password',
]);

新版本

require 'vendor/autoload.php';

use Medoo\Medoo;

$database = new Medoo([
	'database_type' => 'mysql',
	'database_name' => 'name',
	'server' => 'localhost',
	'username' => 'your_username',
	'password' => 'your_password',
]);

Last Insert ID

在1.2之前,调用了insert()方法后将返回新插入的行号.但在1.2之后,你需要调用新增加的API方法 id() 来调用刚插入的id号

旧版本

$account_id = $database->insert("account", [
	"user_name" => "foo",
	"email" => "[email protected]",
	"age" => 25
]);

新版本

$database->insert("account", [
	"user_name" => "foo",
	"email" => "[email protected]",
	"age" => 25
]);

$account_id = $database->id();

新的API方法命名

在1.2之后,取消了原来的驼峰命名,采用了更简单的命名方法

旧版本

$database->insert("account", [
	"user_name" => "foo",
	"email" => "[email protected]",
	"age" => 25
]);

$database->last_query();

新版本

$database->insert("account", [
	"user_name" => "foo",
	"email" => "[email protected]",
	"age" => 25
]);

$database->last();

JSON 声明

在升级1.4后,以前的json声明方式变成了[type],所以旧版本中insert() 和 update()方法的使用方法上也必须升级

旧版本

$database->insert("account", [
	"user_name" => "foo",
	"email" => "[email protected]",
	"age" => 25,
	"(JSON) lang" => ["en", "fr", "jp", "cn"]
]);

$database->update("account", [
	"user_name" => "foo",
	"email" => "[email protected]",
	"age" => 25,
	"(JSON) lang" => ["en", "fr", "jp", "cn"]
], [
	"user_id" => 50
]);

新版本

$database->insert("account", [
	"user_name" => "foo",
	"email" => "[email protected]",
	"age" => 25,
	"lang [JSON]" => ["en", "fr", "jp", "cn"]
]);

$database->update("account", [
	"user_name" => "foo",
	"email" => "[email protected]",
	"age" => 25,
	"lang [JSON]" => ["en", "fr", "jp", "cn"]
], [
	"user_id" => 50
]);

Update, Insert 和 Delete 返回值

在1.4之后,update(), insert()和delete()方法,将不再返回受影响的行数,所以你要使用其它的方法来调用受影响的行

旧版本

$query = $database->insert("account", [
	"user_name" => "foo",
	"email" => "[email protected]",
	"age" => 25,
	"(JSON) lang" => ["en", "fr", "jp", "cn"]
]);

echo $query; // The number of affected row

新版本

$query = $database->insert("account", [
	"user_name" => "foo",
	"email" => "[email protected]",
	"age" => 25,
	"lang [JSON]" => ["en", "fr", "jp", "cn"]
]);

echo $query->rowCount(); // The number of affected row
echo $query->errorInfo(); // Fetch extended error information for this query

// Read more: http://php.net/manual/en/class.pdostatement.php