开发者

PHP ORM _ Connection Management

开发者 https://www.devze.com 2023-02-28 09:33 出处:网络
Which PHP ORM framework is good and light weight , Also having connection pooling and connection management as like hib开发者_StackOverflowernate frameworkBecause of the way PHP is designed to run you

Which PHP ORM framework is good and light weight , Also having connection pooling and connection management as like hib开发者_StackOverflowernate framework


Because of the way PHP is designed to run you won't actually find anything tantamount to Connection Pooling. In fact, the closest you can get is persistent connections, which has it's own pitfalls.

I personally like Propel, although calling it lightweight is sort of subjective. I'm not entirely sure what 'connection management' means but propel is designed to handle multiple database connections as well as master/slave routing based on the query. You can gain speed in the ORM with certain optimizations (APC, Memcached, etc). Things like object hydration also help speed up your application.

Check it out. It's not for everyone.

(For the sake of completion the other popular ORM for PHP is called Doctrine. It's personally not my favorite.)

EDIT

One of the strong points for propel (for me) was it's integration with phing. I think coming from a jboss environment you'll find things like a code deployment process are lacking. For me, phing solves a lot of those issues. As long as I have to have phing installed for propel to work I may as well leverage it for deployments on the entire application.

Phing can roll tar balls, zip files, pear packages or even RPM's if you're feeling brave.


I find db.php orm extremely light and easy also it does not limit connections and you can specify which table for what class is located on which connection:

http://dbphp.net/connect-using-many-links/

The lack of framework is it seems to be newborn and documentation on github repo is updated 2-3 times per week but I already use it in my e-commerce framework and I can say I am fully satisfied.

I dont know if you go in details but when you define connection link in db.php you also specify a desired name for that link like:

$database->link (new \db\link ('my_mysql_link_name', 'mysql:host=127.0.0.1', 'root', '1234'));

And if it is not default link (first link) than you have to specify it to your class (if you have class whose table resides on non-default link database):

/**
* link my_mysql_link_name
*/
class user
{

}

And after you add that class table handler to database:

$database->add ('\user);

Then all queries on that class table handler will be executed on user class specified link:

$database->save (new \user());

So line above will use my_mysql_link_name connection link for query.

I also noticed one interesting thing that if I have relation setup between class properties than db.php fetches related rows (one to one case) with left join in same query if related field tables reside on same connection link otherwise it will use separate queries for fetching related rows for objects (Also you can specify lazy keyword in property doc comment to avoid loading related objects).

Oh and also you can always access your connectins like this: $database->link('name_of_link') or $database->link() for default connection link and you can just add your own class as link to database and override all link methods as described here:

http://dbphp.net/connect-using-custom-link/

And another oh what I like most in db.php is it creates or synchs databases and table structures automatically on all links just by calling $database->update(). <3

0

精彩评论

暂无评论...
验证码 换一张
取 消