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: $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
|