Reply to Is it okay to reuse objects or create new ones everytime....

Your name:

Reply:


Posted by Don Sami on 05/05/06 11:40

I've got a question about reusing object instantances or to creating
new ones. Which is better? Pros and Cons such as open database
connections, overhead, etc?

Right now I am using a Database class for all MySQL operations such
as:

$db = new MySQL();

$db->query("INSERT INTO log (tstamp) VALUE (NOW())");

$db->query("INSERT INTO orders (amount) VALUE ('10.00')");
$order_id = $db->fetchLastInsertId();

Ok now I am still in the same PHP file but should I create a new
database as....

$db->query("INSERT INTO orders_lineitems (order_id, item)
VALUES ($order_id, 'apple pie');

or it is better to create a new instance and then do the same thing...

$new_db = new MySQL();
$new_db->query("INSERT INTO orders_lineitems (order_id, item)
VALUES ($order_id, 'apple pie');


Also I am thinking if there is an error executing the 2nd INSERT INTO
orders query then $db->fetchLastInsertId() would get populated with
the lastInsertId of the INSERT INTO log query. So the $order_id gets
populated with log_id which I don't want. So perhaps using a new
instance is best, am I right or wrong????

execute

TIA

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация