rebeat Posted May 1, 2007 Share Posted May 1, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/49465-solved-inserting-data-from-mysql-what-is-the-best-way/ Share on other sites More sharing options...
bubblegum.anarchy Posted May 2, 2007 Share Posted May 2, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/49465-solved-inserting-data-from-mysql-what-is-the-best-way/#findComment-243067 Share on other sites More sharing options...
rebeat Posted May 2, 2007 Author Share Posted May 2, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/49465-solved-inserting-data-from-mysql-what-is-the-best-way/#findComment-243191 Share on other sites More sharing options...
bubblegum.anarchy Posted May 2, 2007 Share Posted May 2, 2007 The same mysql_connect() that you have in the second line of your own code. Quote Link to comment https://forums.phpfreaks.com/topic/49465-solved-inserting-data-from-mysql-what-is-the-best-way/#findComment-243236 Share on other sites More sharing options...
rebeat Posted May 2, 2007 Author Share Posted May 2, 2007 The same mysql_connect() that you have in the second line of your own code. yes, but does the statement mysql_close(); close all database connections? or do i need to specify the connection, ie: mysql_close(db); ? Quote Link to comment https://forums.phpfreaks.com/topic/49465-solved-inserting-data-from-mysql-what-is-the-best-way/#findComment-243310 Share on other sites More sharing options...
bubblegum.anarchy Posted May 2, 2007 Share Posted May 2, 2007 You do not have to specify any closing database connections that are open via mysql_connect(). Just ignore all my posts!! Quote Link to comment https://forums.phpfreaks.com/topic/49465-solved-inserting-data-from-mysql-what-is-the-best-way/#findComment-243362 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.