473,473 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to access a temporary table created in page1 from page2?

13 New Member
Hi!

Here's my situation:

I created a temporary table TEMP1 in PAGE1.PHP and inserted a few rows. Before I left PAGE1.PHP i tried "SELECT * FROM TEMP1" and echoed the rows and surely there they were.

Then I jumped to PAGE2.PHP using header("Location: PAGE2.PHP") and tried "SELECT * FROM TEMP1" from there and could not echo anymore the rows.

Can anyone pls help me and show me how to access a TEMPORARY TABLE created on one page and accessed its contents (rows) from another page?

A short and simple example will be greatly appreciated.

Learning
Aug 22 '07 #1
7 7475
pbmods
5,821 Recognized Expert Expert
Heya, Learning.

Temporary tables are deleted once you close the MySQL connection (which is done automatically at the end of script execution).

You have a couple of options.
  • You can save the data as an array in the _SESSION until you're ready to commit it to your database. This is probably your best option, as it is the least likely to blow up in your face.
  • You can use MySQL persistent connections. This would preserve your temporary tables because PHP would not close the MySQL connection at the end of the script's execution (more or less), BUT it then becomes up to you to manage your MySQL connections! MySQL will auto-close persistent connections after a certain amount of inactivity, so it's not a huge problem. But I would generally recommend against using persistent connections, as they are usually not necessary and encourage bad habits.
Aug 22 '07 #2
learning
13 New Member
Heya, Learning.

Temporary tables are deleted once you close the MySQL connection (which is done automatically at the end of script execution).

You have a couple of options.
  • You can save the data as an array in the _SESSION until you're ready to commit it to your database. This is probably your best option, as it is the least likely to blow up in your face.
  • You can use MySQL persistent connections. This would preserve your temporary tables because PHP would not close the MySQL connection at the end of the script's execution (more or less), BUT it then becomes up to you to manage your MySQL connections! MySQL will auto-close persistent connections after a certain amount of inactivity, so it's not a huge problem. But I would generally recommend against using persistent connections, as they are usually not necessary and encourage bad habits.
Hi Pbmods,

Thank you for your prompt response to my problem.

I'll try your suggestion right now. But for my better understanding, what do you mean by "at the end of the script execution"? Does this mean at the end of every web page? Does this mean that the MYSQL connection automatically closes everytime it leaves a webpage?

Thanks again. I really appreciate it.

Learning
Aug 23 '07 #3
pbmods
5,821 Recognized Expert Expert
Heya, Learning.

You got it.

When the browser requests a page from your server, the server checks the request and determines (usually by the file extension) what to do with it. So for a .php file, the server will launch the PHP executable and feed the .php file into it.

PHP will then parse the .php script and execute it, including opening a connection to the MySQL database server and playing around with the database.

Once PHP reaches the end of the script, it begins cleaning up and preparing to terminate. It releases the memory it allocated to store variables, closes any files that it opened and it closes its connection to the MySQL database server.

Once it's finished doing all that, the PHP executable itself exits.

Then the server finishes sending the HTML to the browser and then it goes dormant and waits for the next HTTP request.
Aug 23 '07 #4
learning
13 New Member
Heya, Learning.

You got it.

When the browser requests a page from your server, the server checks the request and determines (usually by the file extension) what to do with it. So for a .php file, the server will launch the PHP executable and feed the .php file into it.

PHP will then parse the .php script and execute it, including opening a connection to the MySQL database server and playing around with the database.

Once PHP reaches the end of the script, it begins cleaning up and preparing to terminate. It releases the memory it allocated to store variables, closes any files that it opened and it closes its connection to the MySQL database server.

Once it's finished doing all that, the PHP executable itself exits.

Then the server finishes sending the HTML to the browser and then it goes dormant and waits for the next HTTP request.

Hi again Pbmods,

I've tried your least recommended option cause it was the easiest to try out. And it did work. I'm still finishing the _SESSION array but I'm just wondering,... how do you close a persistent connection?

Again,
Learning
Aug 23 '07 #5
pbmods
5,821 Recognized Expert Expert
Heya, Learning.

Actually, it looks like I have some learning to do, too :P

Using mysql_pconnect() uses a single persistent connection that gets used by the Apache child process.

After a certain number of connections, Apache will terminate and respawn its child processes, which means that the behavior of your script may be a tad unpredictable.

As a result, there is no way to close a persistent connection.

Summer Reading Guide:
Persistent Connections Guide (PHP Manual)
mysql_pconnect() (PHP Manual)
Can I close persistent connections? (FAQTs)
Aug 23 '07 #6
learning
13 New Member
Heya, Learning.

Actually, it looks like I have some learning to do, too :P

Using mysql_pconnect() uses a single persistent connection that gets used by the Apache child process.

After a certain number of connections, Apache will terminate and respawn its child processes, which means that the behavior of your script may be a tad unpredictable.

As a result, there is no way to close a persistent connection.

Summer Reading Guide:
Persistent Connections Guide (PHP Manual)
mysql_pconnect() (PHP Manual)
Can I close persistent connections? (FAQTs)
Thank you so much Pbmods for your time. I'm learning more and more... and I also appreciate the reading guide links. They will be very helpful.

Thanks again.

Learning
Aug 24 '07 #7
rakeshsingh34
1 New Member
hello pbmods!

thank you for such guideline...
Jan 29 '13 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: Carl Gilbert | last post by:
Hi I am currently writing a site that utilises tables. I have one page that links to a second page. The only problem is that when I link to the second page, the table loads up with a...
5
by: yabba | last post by:
2 asp pages From page1 I open a new window... page2. Does page2 know the parent page/wsindow and more inportantly can page2 somehow update the parent page? Something in the form of "<a...
4
by: prasad | last post by:
I am getting sql error during binding a program which access a temporary table. The temporary table declaration and access methods are given below. EXEC SQL DECLARE GLOBAL TEMPORARY TABLE TEM88...
3
by: Avi | last post by:
Hello, I created an access database that is on an ASP page. Utilizing frames (split top and bottom) I would like the top portion to have links of names. When this is clicked, it gets the...
6
by: Bob Sanderson | last post by:
I have created a MySQL database for my company which is accessed by PHP pages. I would like to permit some users to edit the records but allow others read-only access. However, I don't want to have...
1
by: Howard | last post by:
This is what I need to do. User goes to page1.aspx, on that page there's a textbox and a submit button the user types in his name "john doe" then clicks submit. Then the server takes him...
1
by: loga123 | last post by:
I have an aspx page where I am creating "radiobuttonlists" dynamically based on the result from a SQL query. "ID" property of these controls is set dynamically. Then...i have a "submit" button on...
0
by: viral123 | last post by:
Hi I am using asp.net application on server side. I have two web forms as page1.aspx and page2.aspx how can i make change in page2.aspx Lable by clicking on page1.aspx form button. I really...
0
by: bogdan | last post by:
Hi, I'd like to make sure that users access pages in a specific sequence. For example, if a site consists of 3 pages, I'd like users to access first Page1.aspx, then Page2.aspx, and then...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.