Jump to content

Stop doing so many connections:


Anders Moen

Recommended Posts

Hey!I can't remember the last time I started a topic in the PHP forum here now, but anyways;If I do this: (over doctype)

<?phpsession_start();mysql_connect("localhost", "username", "password");mysql_select_db("my_db");?>

And in ... body I would do this:

<?phpecho 'This is all of our members<br /><br />';while($row = mysql_fetch_array(mysql_query("SELECT * FROM table WHERE language = 'english' ORDER BY id DESC LIMIT 12))) {echo $row['username'];echo '<br />';}?>

Would this work? If you don't understand;I do the connection in the start of the page, and then I select from tables some random places in the body just to limit the connections? In example I really have to do ... 20 connections, but can this be limited to 1 by doing this?Thanks in advance!

Link to comment
Share on other sites

Hi...No that would not be work even if with tthe persistan link also with mysql_pconnect();If you found the other way then tell me...you can do the following (probably that u know..):

<?phpsession_start();$link=mysql_connect("localhost","root","");$sel_db=mysql_select_db("db_name");$qry="SELECT * FROM table WHERE language = 'english' ORDER BY id DESC LIMIT 12";$result=mysql_query($qry,$link);echo 'This is all of our members<br /><br />';while($row = mysql_fetch_array($result)){	echo $row['username'];	echo '<br />';}?>

Regards,Vijay

Link to comment
Share on other sites

Well, what I meant was that when I made the CMS on my old website, if you have seen it (www.andersmoen.hotserv.dk/cms/), I did so many connections. About 15 connections if I don't remember wrong.And I was just wondering if it would work if I just connect on the top of the page, and then put the mysql_query(select ...) some places so I go from 15 connections to 1?

Link to comment
Share on other sites

Hi..yes you can do for thatyou have to common connection code @ one file "connect.php"and that file you have to require_once @ where ever you want..I mean suppose this you want to say..am i right..?Regards,Vijay

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...