Any PHP Gurus wanna answer a question for me?

    Date: 11/26/05 (Computer Geeks)    Keywords: php, programming, mysql, browser, html, database, asp, sql

    I've done plenty of ASP.NET programming but this is my first foray into the wonderful land of PHP and I've got a question about how often you hit the database in a normal page load... basically I have tags like:

    within the front end page and listing.php goes something like

    $database = mysql_connect("localhost", "your_database_user_id", "your_database_password");
    mysql_select_db("your_database_name", $database);
    
    switch($type){
    	case 'thumbnail':
    		header("Content-type: image/jpeg"); // act as a jpg file to browser
    		$query = "SELECT thumbnail
    			FROM your_table
    			WHERE id = $id";
    		$result = mysql_query($query, $database);
    	
    		$row = mysql_fetch_array($result);
    		$jpg = $row["thumbnail"];
    		echo $jpg;
    		break;
    	case 'address':
    		header("Content-type: text/html"); // act as an html file to browser
    		$query = "SELECT address
    			FROM your_table
    			WHERE id = $id";
    		$result = mysql_query($query, $database);
    	
    		$row = mysql_fetch_array($result);
    		$address = $row["address"];
    		echo $address;
    		break;
    }
    

    Now if I understand this correctly, anytime the parser hits a tag (or w/e) it will connect to and select from the database. So on a page with 5 tags that pull from listings.php, the scripts will connect to, select from and disconnect from the database 5 times right? Is this is proper way to do things? It kinda makes me uncomfortable to make so many database hits but this seems to be the average way php developers do it.

    Source: http://www.livejournal.com/community/computergeeks/824527.html

« Holodisks. 2006. || AGP Card Question »


antivirus | apache | asp | blogging | browser | bugtracking | cms | crm | css | database | ebay | ecommerce | google | hosting | html | java | jsp | linux | microsoft | mysql | offshore | offshoring | oscommerce | php | postgresql | programming | rss | security | seo | shopping | software | spam | spyware | sql | technology | templates | tracker | virus | web | xml | yahoo | home