Jump to content

[SOLVED] Inserting data from mysql... what is the best way?


rebeat

Recommended Posts

Hi,

 

Just wondering what the best method to insert a value from a database is. Does it need to include the username/password to grab the value, because my site has a lot of items, each page would need to update the price for that item from the database, so one visitor could visit 30 pages, each page has to open the database to extract. Does this slow the server down?

 

this is the method i am looking at:

<?php
$db = mysql_connect("localhost", "user", "pass");
mysql_select_db("products",$db);
$result = mysql_query("SELECT * FROM products WHERE id=4", $db);
$myrow = mysql_fetch_array($result);
?>

<?php echo "Our Special Price is <b>$".$myrow["special2"]."</b>" ?>
<?php mysql_close() ?>

 

Is this the best way?

 

also is it a good idea to include <?php mysql_close() ?> in the footer to prevent it remaining open?

 

 

Cheers.

 

FYI: mysql_connect() assures that the connection is closed when the script is complete so there is no need to add mysql_close(), unless you want to be super safe.

 

does mysql_connect() close the mysql connection? do i need to enter any value between () ? thx.

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.