|
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]
|