PEAR Forum :: PHP Extension and Application Repository

PEAR Forum Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
MDB2: Anything else I should do with my connection?

 
Post new topic   Reply to topic    PEAR Forum Forum Index -> Database
View previous topic :: View next topic  
Author Message
Jesdisciple



Joined: 24 Mar 2008
Posts: 11
Location: Texas

PostPosted: Wed Mar 26, 2008 8:14 am    Post subject: MDB2: Anything else I should do with my connection? Reply with quote

Currently I have this sequence working; should I add/change any thing? (I'm picking up bits and pieces of the Getting Started guide that no one has compiled yet.)
Code:
$driver =& MDB2::connect(/*...*/);
$driver->beginTransaction();
///...
$driver->query(/*...*/);// actually in a foreach
$driver->commit();
$driver->disconnect(false);


Thanks!
Back to top
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 1048

PostPosted: Wed Mar 26, 2008 11:04 am    Post subject: Reply with quote

The disconnect() call is optional, as PHP will close the connection to the database anyway. But could consider it more clean to close the connection yourself.

Depending on what you're really doing in the query() call, you might want to consider using the prepare/execute feature, as explained here:
http://pear.php.net/manual/en/package.database.mdb2.intro-execute.php
http://pear.php.net/manual/en/package.database.mdb2.intro-auto.php
Back to top
View user's profile Send private message
Jesdisciple



Joined: 24 Mar 2008
Posts: 11
Location: Texas

PostPosted: Thu Mar 27, 2008 12:07 am    Post subject: Reply with quote

For the full source and API of that file, see http://code.google.com/p/error-logger/source/browse/trunk/error-logger.xml, http://code.google.com/p/error-logger/source/browse/trunk/xml.php, and http://code.google.com/p/error-logger/source/browse/trunk/prune.php.

Would there be any advantage to using prepare in this case (probably by changing my %-enclosed placeholders to ?s)?
Back to top
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 1048

PostPosted: Thu Mar 27, 2008 12:16 am    Post subject: Reply with quote

Sorry, I'm too lazy tonight to have a deeper look into your code. prepare() and execute() are interesting if you're using queries multiple times (i.e. same query but different values).

This feature might look a little bit weird at first, but once you've understood the concept, it's really nice and handy (of course, only if the usage makes sense; see above).
Back to top
View user's profile Send private message
Jesdisciple



Joined: 24 Mar 2008
Posts: 11
Location: Texas

PostPosted: Thu Mar 27, 2008 12:48 am    Post subject: Reply with quote

Woops, I thought you were suggesting that I should present the full source.

I was uncertain whether I should alter my code because I had a similar system established, except I used named placeholders exclusively and I prepared my statements once per query. (The purpose of the system was primarily to store my queries in XML, so I hadn't considered a prepare-execute setup.)

But I'm trying it; if I run into too much trouble I'll just go back in SVN.

Thanks!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    PEAR Forum Forum Index -> Database All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



PEAR Forum topic RSS feed 
Powered by phpBB © 2001, 2005 phpBB Group

Provided by Ministry of Web developement

'Actiemonitor' online projectmanagement software