Solved

Moving the mysql connection to the next web page

Posted on 2003-12-03
5
251 Views
Last Modified: 2006-11-17
I'm running linux/php/apache to manipulate a mysql data base.

The user enters a userId and password. I connect to the mysql data base using -

$linkId = mysql_connect( 'localhost', $userId, $password );

And I can do some queries, etc. (it's fine up to here).

Via a "submit" button, I go to another web page. I want to do more data base queries in this page.

Do I have to do another mysql_connect in the next web page?
Do I have to pass the userId and password to the next web page via hidden text fields?
Can I send the $linkId to the next web page? (equals "resource id #1" or some such. Doesn't work)


0
Comment
Question by:rfr1tz
  • 3
5 Comments
 
LVL 3

Accepted Solution

by:
ashoooo earned 200 total points
ID: 9868358
You can close the db connection and open a new one on every page... doesnt take a lot of resources.

As for the username and password, you can store them in session variables.
0
 
LVL 3

Author Comment

by:rfr1tz
ID: 9868456
OK, so if I set a session variable on web page 1, can I reference and use it on web page 2.

I tried session variables. The web page where the variables were set seemed to remember the values, but the other web pages didn't know anything about these variables.

User error??
0
 
LVL 3

Assisted Solution

by:ashoooo
ashoooo earned 200 total points
ID: 9868715
You need to start the session on each page using the session_start() function.
0
 
LVL 3

Assisted Solution

by:ashoooo
ashoooo earned 200 total points
ID: 9868719
Dont forget to close the db connection on each page using mysql_close($linkId);
0
 
LVL 6

Assisted Solution

by:aolXFT
aolXFT earned 50 total points
ID: 9869035
normally you open a different mysql connection for each webpage you view.

If you want to reduce the connection overhead, and connect only once check out mysql_pconnect. mysql_pconnect only works if you are using an apache module.

You cannot maintain a connection between different CGI scripts.

www.php.net/mysql_pconnect
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now