There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
access audio avg avg 8 boot bsod computer cpu crash css dell desktop driver drivers dvd email error excel explorer firefox firefox 3 freeze gimp graphics hard drive hardware help please hijackthis hjt hjt log install internet internet explorer itunes javascript keyboard lan laptop log malware monitor network networking outlook outlook 2003 outlook express password php popups problem router seo slow sound sp3 spyware startup trojan usb video virtumonde virus vista vundo windows windows vista windows xp winxp wireless youtube
Web Design & Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Internet & Networking > Web Design & Development >
Solved: Open mysql database once over several pages?


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

 
Thread Tools
colinsp's Avatar
Computer Specs
Senior Member with 110 posts.
 
Join Date: Sep 2007
Location: Spain
Experience: Adv PC, int HTML, noob PHP
15-May-2008, 01:29 AM #1
Solved: Open mysql database once over several pages?
I am just getting to grips with php and mysql so forgive the maybe simple question.

I have a mysql database with two tables in it names and users. I have a login page that checks the user credentials against the user table and if successful sets a session and then opens a second page displaying the data from the names table.

I developed the login script and the data display forms separately and both work perfectly. I think that I have an issue though in that both pages set a link to the database with their own msql-connect statements. I would have thought that I only need to open the database once but I can't see how to pass the database settings from one page to the other.

Do I need to worry about this or is it a performance / security / whatever issue? If so how do I pass the information?

TIA.
TheRobatron's Avatar
Computer Specs
Senior Member with 391 posts.
 
Join Date: Oct 2007
Location: England
Experience: Intermediate
15-May-2008, 12:10 PM #2
It would be easier if you put both sets of data in one table, then you can select different columns from the same row. If not, you could create an ID column and link the two tables with each row in one table having a corresponding row in the other, with the same ID.
__________________
There's no place like 127.0.0.1

colinsp's Avatar
Computer Specs
Senior Member with 110 posts.
 
Join Date: Sep 2007
Location: Spain
Experience: Adv PC, int HTML, noob PHP
15-May-2008, 12:28 PM #3
Sorry maybe I didn't make myself clear. The users table contains the user id's and passwords of 5 people who have access to the data contained in the names table. Does that make any difference to your reply? I can't see how your suggestion would help with not calling the mysql-connect twice as they are two separate forms. I suppose what I am really asking is there a way to pass the open database details from one page to a second page?
tomdkat's Avatar
Computer Specs
Distinguished Member with 2,994 posts.
 
Join Date: May 2006
Location: S.F. Bay Area, CA
Experience: Intermediate
15-May-2008, 12:34 PM #4
I think you should study up on Persistent database connections. Get familiar with the concepts (which will also apply to MySQL) and decide if that's right for you.

Here are a couple of pages from that Google search to help get you started:

http://www.phpbuilder.com/manual/en/...onnections.php
http://www.mysqlperformanceblog.com/...nections-evil/

Peace...
colinsp's Avatar
Computer Specs
Senior Member with 110 posts.
 
Join Date: Sep 2007
Location: Spain
Experience: Adv PC, int HTML, noob PHP
15-May-2008, 12:54 PM #5
Thanks I'll check those links out.
Mudley's Avatar
Computer Specs
Member with 99 posts.
 
Join Date: Apr 2008
Experience: Advanced
15-May-2008, 03:50 PM #6
you could certainly try persistent connections, but i don't think you need to worry about it.
If you're on a hosted/shared environment, i wouldn't bother. Persistent connections often requires additional administration of mysql...

opening the connection, performing the query and closing the connection is fast and efficient in mysql.
colinsp's Avatar
Computer Specs
Senior Member with 110 posts.
 
Join Date: Sep 2007
Location: Spain
Experience: Adv PC, int HTML, noob PHP
15-May-2008, 04:24 PM #7
Mudley, Thanks for that I have just finished reading about persistent connections form the links that Tomdkat mentioned and a couple of others on Google and that was the conclusion I had come too. It is a relatively small database with only 1 or 2 concurrent users so I can't see that I will have any problems. Thanks to everyone for their help on this I will mark it as solved.
tomdkat's Avatar
Computer Specs
Distinguished Member with 2,994 posts.
 
Join Date: May 2006
Location: S.F. Bay Area, CA
Experience: Intermediate
15-May-2008, 04:42 PM #8
Quote:
Originally Posted by Mudley View Post
opening the connection, performing the query and closing the connection is fast and efficient in mysql.
I also agree with this.

Peace...
Reply

Tags
mysql, persistent connection, php


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are Off
Refbacks are Off

You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 11:04 PM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.