thinkPHP如何实现ORM?

WBOY
Release: 2016-06-06 20:46:49
Original
1572 people have browsed it

PHP如何实现ORM?类似于Hibernate这样的?有哪些框架或者类库可以帮助实现?

回复内容:

PHP如何实现ORM?类似于Hibernate这样的?有哪些框架或者类库可以帮助实现?

重一点的功能全一点的可以用doctrine, annotation用起来还是很爽的

Yii,CakePHP……

ORM的话不是官方自带的PDO类就行了么?http://cn2.php.net/manual/zh/book.pdo.phpX3X

(一直以为ORM和数据库操作是一个意思,然后就武断的说了PDO,咳咳)...

回答这个问题的主要目的是来推荐类库的啦,我一般使用 http://medoo.in 这款,个人觉得非常不错的哦,顺带说一句,是 http://catfan.me 写的呢。

相当多的主流框架用的是 Active Record 实现的 ORM, 一样用、

推荐:http://www.notorm.com/
PS:PHP没有真正的ORM.

可以试一下arraydb,这个是infoq对arraydb的介绍 http://www.infoq.com/cn/articles/arrayDB

推荐一个短小精悍的ActiveRecord库,lloydzhou/activerecord · GitHub, 可以实现类似Yii的relation的效果。文档地址:http://lloydzhou.github.io/activerecord/

<code>class User extends ActiveRecord{
  public $table = 'user';
  public $primaryKey = 'id';
  public $relations = array(
    'contacts' => array(self::HAS_MANY, 'Contact', 'user_id')
  );
}
class Contact extends ActiveRecord{
}
$user = new User();
// find one user
var_dump($user->notnull('id')->orderby('id desc')->find());
echo "\nContact of User # {$user->id}\n";
// get contacts by using relation:
//   'contacts' => array(self::HAS_MANY, 'Contact', 'user_id'),
var_dump($user->contacts);</code>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template