Doctrine FAQ
- Can I generate my Doctrine schema/models from an existing database?
- Can I specify my mapping in something other than PHP?
- Can I use Doctrine with a MVC Framework?
- Can I use Raw/Native SQL with Doctrine?
- Does Doctrine scale / does it prevent my application from scaling (out)?
- Does Doctrine support inheritance?
- Does Doctrine support many2many relationships?
- How can I log all my executes queries?
- How can I update a record without retrieving it first?
- How can I upgrade my database when my schema changes?
- How do I lazy load my model classes?
- How do I submit a bug?
- What is the best way to get started with Doctrine?
-
Can I generate my Doctrine schema/models from an existing database?
Yes. Doctrine offers a database import feature which will generate your php models or yaml schema files from an existing database.
-
Can I specify my mapping in something other than PHP?
Yes. Doctrine offers the ability to optionally specify your mapping as a set of YAML files or even in the form of XML files (2.0+). You can read about yaml files here.
-
Can I use Doctrine with a MVC Framework?
Yes. Doctrine has already been successfully integrated with several well known PHP frameworks. Symfony and Zend Framework are the two largest and widely used frameworks with Doctrine.
-
Can I use Raw/Native SQL with Doctrine?
Yes. Doctrine offers the ability for you to write raw SQL statements and let Doctrine map the result into objects (or arrays, or a scalar result set). Apart from that you can always use plain SQL as you would do it without Doctrine.
-
Does Doctrine scale / does it prevent my application from scaling (out)?
Doctrine scales like any other PHP software, which usually means that the bottleneck becomes the poor database since the PHP servers push all their shared state there. And database servers can usually not be added as easily as PHP servers because they need to synchronize their data in some form or another (think replication).
As such, a crucial aspect to scaling out with PHP and probably any other large website, no matter the technology, is usually to make good use of caches, among other things to alleviate database load.
Doctrine does not prevent you from scaling (out).
Some things to watch out for during development, with or without Doctrine:
- * Monitor your database queries. That is well known.
- * Monitor your memory usage. Many people only observe the raw rendering speed of their site, this is not enough. As PHP servers dont keep any state between web requests, all the memory that is needed to process a single request is allocated and deallocated over and over. Keeping your memory usage low positively affects both the performance and scalability of your site. To help keep your memory usage low when using any kind of larger PHP library, please use APC or another opcode cache. Parsing lots of PHP code on each request eats a lot of memory.
Invaluable tools for scaling (out) your PHP application, with or without Doctrine:
* APC
* Memcached (once your site outgrows a single server)
Also, please be aware that there is no point in letting Doctrine load thousands of objects and/or do 10-20+ joins and then complaining that it is slow. It's just doing what you told it to do, and yes, its trying to do that as good as it possibly can. Doctrine gives you all the flexibility to walk up and down in the abstraction levels as you wish. Dont need an object graph? Fetch an array graph. Dont need an array graph? Fetch a plain SQL result set. Dont want to use DQL? Use SQL. But be aware of premature optimization! Doctrine does not take away the tools you had before, it just gives you more tools and the possibility to develop on a higher abstraction level, if you want to.
With all that said, if you think you found a real bottleneck in the Doctrine PHP code that is not related to database operations or general I/O, please let us know through JIRA, so that we can take care of that.
-
Does Doctrine support inheritance?
Yes. Currently Doctrine supports three types of inheritance and they are: Simple, Concrete and Column Aggregation inheritance. You can read more about inheritance here.
-
Does Doctrine support many2many relationships?
Yes. Doctrine fully supports many2many relationships, as well as self referencing ones.
-
How can I log all my executes queries?
Doctrine has the ability to log all executed queries on a connection instance by using the connection profiler which can be read about in the manual here.
-
How can I update a record without retrieving it first?
Doctrine offers the ability to specify update statements with DQL.
-
How can I upgrade my database when my schema changes?
Doctrine offers this functionality via the migrations feature. It allows you to programatically write upgrade classes which alter an existing database schema. Doctrine also offers features which will automatically generate these upgrade classes for you.
-
How do I lazy load my model classes?
Doctrine offers a method for lazy loading models called conservative model loading. You can read about what it is and how you can take advantage of it here.
-
How do I submit a bug?
You can submit a bug via Jira. It is required that you signup to create a new issue. It also is recommended that you write a failing test case for your issue, you can read about test cases here.
-
What is the best way to get started with Doctrine?
The best way to get started is to read the The Guide to Doctrine and follow the code examples.
