13

The quote below has convinced to finally go ORM. In the past I havn't really liked ORM and wrote it off as a stupid way of doing sql. Dealing with hierarchical data in sql is a pain I don't want to deal with.

There's a reason we have these “Object-Relational Mapper” things, and it's because of a problem known as the Object-Relational Impedance Mismatch. Basically, the formal mathematical model for databases used to ensure that they stay intact follows a system of tables with rows and columns and references to other tables, while data structures in most programming languages we use today manipulate data in nested tree-like structures. It's rather like the difference between a spreadsheet and an XML document, or between a ledger and a family tree diagram. - http://zork.net/motd/nick/django/your-favorite-orm-sucks.html

I want something with minimal effort to setup. Most of my project are small so I don't want to spend much time defining models when I only use them for few queries.

I'm using codeigniter as the php framework and MySQL as the database.

Benbob
  • 13,876
  • 18
  • 79
  • 114
  • 1
    possible duplicate of [Good PHP ORM Library?](http://stackoverflow.com/questions/108699/good-php-orm-library) and [many others](http://stackoverflow.com/search?q=orm+php) – Gordon Aug 09 '10 at 07:52
  • 2
    Hierarchical data in a database that doesn't have any recursive or hierarchical query support is your issue. PostgreSQL would be a viable alternative, though there are free versions of SQL Server and Oracle available these days... – OMG Ponies Aug 09 '10 at 07:54
  • @OMG Ponies So basically the problem is mySQL does not support objects so the only way to get the data out is to either recursively query or do a bunch of left joins and end up with redundant data? I've only dealt with oracle briefly, a stored procedure is the correct tool for this or can the query actually return hierarchical data in objects? – Benbob Aug 09 '10 at 08:13
  • 1
    Oracle has had hierarchical query support since v2, using the `CONNECT BY` syntax. The ANSI way to do it is with a recursive WITH clause, which Oracle didn't support until 11g R2 while SQL Server 2005+ was (which lead to the ANSI acceptance). I'm not clear on what version of PostgreSQL started recursive WITH suppport - 8.x I believe. – OMG Ponies Aug 09 '10 at 08:21
  • @OGM Ponies I looked up the oracle example and it looks very neat. I guess the easiest way to get a tree of an arbitrary length is to left join and use some php loops to move everything into a nested array. That would be easier than setting up ORM for my small projects I think. Anything beats recursive querying. Unfortunately I'm stuck with MySQL but it's interesting to read about WITH RECURSIVE and CONNECT BY – Benbob Aug 09 '10 at 23:53

5 Answers5

9

Doctrine is brilliant and very easy to setup and use with CI. There are three ways of integrating it 1) the way described in the CI wiki 2) as a plugin 3) using hooks. I don't like option 1 as it involves messing with CI system files. Option 2 is very easy and what i currently use. Setup is described at www.phpandstuff.com. I've never tried option 3 but it sounds interesting - http://blog.medryx.org/2008/10/04/codeigniter-and-doctrine/

musoNic80
  • 3,678
  • 9
  • 40
  • 48
5

I think you should try the DataMapper ORM which is written in native CI Also easy to configure and easy to use as well. I think it's better than Doctrine.

tlarevo
  • 51
  • 1
  • 1
4

Here are the ones I use

  1. Doctrine

  2. DataMapper

Gilles 'SO- stop being evil'
  • 104,111
  • 38
  • 209
  • 254
Flakron Bytyqi
  • 3,234
  • 20
  • 20
2

I would recommend

http://www.doctrine-project.org/, it is very popular so you will have knowledge, and will be able to use it in other framworks.

Centurion
  • 5,169
  • 6
  • 28
  • 47
2

How about Datamapper Overzealous Edition

I think that the original DataMapper (from stensi) isn't under development anymore. (Someone correct me if I'm wrong) Datamapper Overzealous Edition is easy to get working with Codeigniter.

I'm sure Doctrine works well too, but I'm not sure how easy it is to set up with Codeigniter.

Matthew
  • 15,282
  • 27
  • 88
  • 123