Solved

Moving the mysql connection to the next web page

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
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 …
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

911 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

23 Experts available now in Live!

Get 1:1 Help Now