Fastest way to retrieve results from db

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kingconnections
Forum Contributor
Posts: 137
Joined: Thu Jul 14, 2005 4:28 pm

Fastest way to retrieve results from db

Post by kingconnections »

Ok so I often code things in such a manner:

Code: Select all

dbconnect string 

blah blah 

while ($row = mssql_fetch_assoc($result3)){ 
       			      			
foreach ($row as $col2=>$val2){
do some stuff

}


}
That allows me not to have to reference the columns directly. I could have said

Code: Select all

while ($row = mssql_fetch_assoc($result3)){ 
       			      			
$val=$row['fieldname here'];

}

What is the fastest and most effective way to retrieve the results?
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post by infolock »

The second method.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

It really depends on whether you want your code to know the field names or not. If you want code that works with any table then the first one. If you know the specific column names and the code only deals with that table then the second.
(#10850)
Post Reply