TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 04-02-2008, 02:29 AM   #1 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default Class desconstruct/available resources

I'm sure everybody will say yes to this, but... if I have a class that opens a connection to my database when its called, should I worry too much about setting up a __destruct that closes it and unset() at the end of every page? The page has already loaded, accessed all its functions and displayed everything... there's no open connections after the person leaves the page anyways, right?
__________________
uʍop ǝpısdn sı ɹǝʇndɯoɔ ɹnoʎ sıɥʇ pɐǝɹ uɐɔ noʎ ɟı
delayedinsanity is offline  
Reply With Quote
Old 04-02-2008, 02:49 AM   #2 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

Another question, not really relating, but kind of - I'm building a small customer support system for my site, and at the top of each administrative page I list the total posts, total new posts, and total posts awaiting reply (read but not replied).

As of now I have three seperate functions, dbTotalPosts(), dbNewPosts(), dbWaitingPosts(), each doing their own database query (SELECT ticket FROM contact, SELECT ticket FROM contact WHERE new='1', etc). All of them use the same db connection, they're not opening and closing it, so is this okay, or would it be better to do one query (SELECT new, replied FROM contact) and then loop through the results and provide a $count of each row? ($total++, $new++, $replied++, or I guess just $new++, $replied++ $total = $new + $replied)

Thanks in advance,
-m
delayedinsanity is offline  
Reply With Quote
Old 04-02-2008, 04:31 AM   #3 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default The Code

First question is still my most important, but here's the code I just wrote quick to reduce the number of database calls from 3 to 1.

PHP Code:
// dbPostCount - counts total posts, new posts, and posts awaiting response
function dbPostCount() {
    
$query "SELECT new, replied FROM " TBL_CONTACT;
    
$result mysql_query($query$this->connection);
    
    while (
$row mysql_fetch_row($result))
    {
        
$c['total']++;
        if (
$row[0] == "1") { $c['new']++; } elseif ($row[0] == "0" && $row[1] == "0") { $c['waiting']++; }
    }
    
    return 
$c;

Can I improve on this? I'm willing to bet just from the 3 to 1 database calls that it IS quicker than my original method.
-m
delayedinsanity is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 10:39 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design