Solved

Moving the mysql connection to the next web page

Posted on 2003-12-03
5
276 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

776 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