PHP Orm与来自模型的数据库 [英] Php Orm with database from model

查看:63
本文介绍了PHP Orm与来自模型的数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很习惯Django.使用Django,您可以为ORM定义模型,并负责生成/更改数据库本身以基于模型存储数据.

I'm pretty used to Django. With Django you define your models for the ORM and it takes care of generating / altering the database itself for storing the data based on the models.

在php中,我正在寻找类似的解决方案.学说似乎是标准的PHP ORM,但据我所知,您必须编写数据库并 then 附加到数据库上,或编写数据库脚本,然后 then 生成模型并开始工作.

In php i'm looking for a similar solution. Doctrine seems to be the standard php ORM, but, as far as I've seen, you have to write the DB and then attach to it, or script the database creation, then generate the models and start working.

使用Doctrine或其他php orm解决方案创建数据库是否需要一步模型定义?谢谢.

Is there a one step model definition to db creation with Doctrine or another php orm solution? Thanks.

推荐答案

您是否仅Django本身中的ORM负责创建数据库和所有其他内容?

Are you that only the ORM in Django itself is responsible for creating the DB and all that stuff?

但是Doctrine可以执行

But Doctrine can do the setup automatically. I copied the most important part:

// generate.php

require_once('bootstrap.php');

Doctrine_Core::dropDatabases();
Doctrine_Core::createDatabases();
Doctrine_Core::generateModelsFromYaml('schema.yml', 'models');
Doctrine_Core::createTablesFromModels('models');

schema.yml包含 YAML 格式的表定义.

在您已经在谈论框架时,您可以看看 Symfony 您想要的东西很多,并且为此提供了更简单的界面(比Doctrine本身).您可以将Propel或Doctrine用作ORM.

As you are already talking about frameworks, you might have a look at Symfony which does pretty much the things you want and which provides an even easier interface for it (than Doctrine itself). You can either use Propel or Doctrine as ORM.

这篇关于PHP Orm与来自模型的数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆