Jump to content

is this wrong?


sniperscope

Recommended Posts

Hi all.

I always create my sql queries like below.

        $user	= "user";
$pass	= "123456";
$host	= "localhost";
$base	= "test";

$cn = mysql_connect($host, $user, $pass) or trigger_error("SQL", E_USER_ERROR);
mysql_select_db($base,$cn) or trigger_error("SQL", E_USER_ERROR);

       $QUERY = mysql_query("SELECT id FROM someTable", [size=14pt][color=red][b]$cn[/b][/color][/size]) or die(mysql_error());

while ($list = mysql_fetch_assoc($QUERY)){
              echo "Some Text over loop";
        }

 

Okay here is the question (or problem). What if i have 5000 records in my Table. Doesn't this code connect DB 5000 times?

If yes, then how can i optimize it?

Link to comment
https://forums.phpfreaks.com/topic/225695-is-this-wrong/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.