Jump to content

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


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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.