Domain: phpdb.org
Stories and comments across the archive that link to phpdb.org.
Comments · 11
-
Re:This coming from the DB Community?If SQL is so cool, then why don't we have a different PL for each task? SQL (Structured Query Language) isn't a programming language. It's a client/server communication protocol. When you use a database, your program (the client) is calling the database (server). You need to have some protocol for that communication. SQL is more on par with FTP or HTTP than PHP.
Now, it's quite reasonable to want to abstract out that communication in your code. For many applications, you won't care about the underlying database implementation and can manage with just create, read, update, and delete operations. That's why Object Relation Mappers (ORMs) exist. It sounds like Symfony (which I haven't used) implements an ORM. A pretty common ORM for Java is Hibernate. An ORM can make things easier for many tasks. However, in practice, one occasionally finds that an ORM does not support asking the questions that actually need answered. SQL does. That's why Hibernate still allows people to write direct SQL.
Another issue is that SQL isn't always used from a programming language. It's quite common to connect to a database directly and query with SQL. It would be very inconvenient to have to write a PHP program every time I wanted to query the database. It's much easier to use SQL either on an ad hoc basis or via a script.
If ORMs are enough for you, that's great. In my experience, they aren't enough for me and I need something with the flexibility of SQL.
You can see an example of a query that's simpler in SQL than in Propel at http://propel.phpdb.org/trac/wiki/Users/Documentation/1.3/ManyToManyRelationships
They basically implement something along the lines of
for each book in DB
get the reader line mapped by the book_reader table
This takes about seven lines of code and forces the program to call the database n+1 times (where n is the number of books). SQL can express the same question in a single query. If there are a small number of readers and a lot of books, this can significantly reduce the request/reply overhead. I suspect that Propel would also have trouble with questions that would require a left join. I suspect that it would require the same kind of application level mapping of something that the database already implements. -
Re:Bad programmers are still bad programmers!
but real-world PHP-programmers don't even use joins or subselects."
Real world PROGRAMMERS, even PHP programmers, use libraries to abstract DB access out as much as possible. Otherwise, these aren't programmers. Hackers, maybe, but not programmers. For PHP, Creole with either Jargon or Propel seem to work very well.
In any case, if your query needs more than one line to be expressed, you should move it into the DB, and create a stored procedure.
-
Re:Bad programmers are still bad programmers!
but real-world PHP-programmers don't even use joins or subselects."
Real world PROGRAMMERS, even PHP programmers, use libraries to abstract DB access out as much as possible. Otherwise, these aren't programmers. Hackers, maybe, but not programmers. For PHP, Creole with either Jargon or Propel seem to work very well.
In any case, if your query needs more than one line to be expressed, you should move it into the DB, and create a stored procedure.
-
Re:If you're going to be this generic...
Actually you could make this class totally generic by having it query the DB for all the field information. That could even include validation to make sure the input is the right type, length, etc. All the info you need for that is in the DB. The problem is that, unless you're just writing a generic DB table editor app, you generally need unique methods for each table/object.
If you find this kind of thing interesting, it's probably worth checking out some persistance layers like hibernate or (for PHP) Propel -
Re:I'm sorry but I, almost, completely disagree
-
PHP 5It is worth mentioning that PHP 5 is catching the attention of more and more java developers as well. Frameworks like
- Mojavi (MVC framework ie: Java Struts)
- Propel (ORM framework ie: Apache Torque / Hibernate)
- Prado (Component-based and Event-driven framework ie: asp.net)
are helping PHP move from being a micky mouse scripting tool for joe web designer's guestbook to a tool used to create full blown web applications. - Mojavi (MVC framework ie: Java Struts)
-
Re:Hmmm, what for?
My question is: Is there something similar to Hibernate for PHP?
The closest thing to Hibernate that I can think of is Propel. -
Propel.
Propel is the best I've seen. I'm not a java programmer but apparently its based on a similar java framework.
http://propel.phpdb.org/docs/user_guide/ -
Re:Congratulations are in order!
Just because you use a good abstraction strategy doesn't mean you have to actually implement the code for every platform. I just write for the one that I need at the time & I can use as much platform-specific code as I want. But, having a strategy in place so you can plugin a new DB later is comforting.
As much as I hate to give up my SQL code, persistance layers for PHP like Propel and PEAR DataObject seem to be maturing nicely. DB abstaction becomes (in theory) a mute point. I'm really anxious for PHP 5 to become more widely installed so I can take advantage of these technologies that are already in production status for Java and .NET code. -
Re:Congratulations are in order!Another db abstraction layer you might want to look into is Creole.
It's built for PHP5 but there is also a php4 back port made to support another project.I've been using it for a little while and really like what I see.
http://creole.phpdb.org/wiki/ -
Re:jsp is a bad idea, but Java is not