Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Temporary tables and mysql_pconnect

Status
Not open for further replies.

overyde

Programmer
May 27, 2003
226
ZA
now this has me puzzled!!!

I have a script that uses a mysql_pconnect and a temporary table over 2 pages. The first page creates the temporary table and inserts some available data and displays a form, the second page displays the data (confirmation page) and inserts the posted data into the temporary table.

Problem is it does it SOMETIMES?!?!? Sometimes it seems it does not find the table. BUT...if you press the back button on the browser and re enter the data and post it again...IT WORKS???

What the heck is going on here???

Reality is built on a foundation of dreams.
 
The error message I get is as follows:
Code:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\Program Files\Apache Group\Apache2\htdocs\giftsongs4\secure\checkout\checkoutc.php on line 39

Reality is built on a foundation of dreams.
 
One other thing...if I have a page another web page open, it will work as well???

Reality is built on a foundation of dreams.
 
What do you mean by "temporary table"? At first blush, this doesn't sound like a good idea to me when using mysql_pconnect().


Your code is also not checking the return from mysql_query() to make sure that FALSE was not returned. If your script were to output mysql_error() when FALSE is returned by mysql_query(), you would have more debugging information to go with.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
This is my script that creates a temporary table.
Code:
$sql4 = mysql_query("CREATE TEMPORARY TABLE $_SESSION[table] (id int(20) NOT NULL PRIMARY KEY auto_increment, questnum int(20), quest_field int(20), question VARCHAR(200), answer VARCHAR(200))", $conn);
my client doesn't have the priveledge of innodb tables so transactions are not possible here and he can not have "orphan" tables or records lying on his dbase.


Reality is built on a foundation of dreams.
 
When mysql_query() does not return a result resource, what does mysql_error() return?

What is in $_SESSION['table']? How does the value get there?

At what time are you deleting the tables? If you're using mysql_pconnect(), the connection doesn't close between script runs, so the tables will be there. Unless you explicitly drop the tables, you're going to create a lot of them and leave them lying around.

If you need to store some scratch data in a table, just use a permanent scratch table. With the auto_increment column (BTW, INT UNSIGNED works better than INT with auto_increment columns) your first script could insert data when it needs to, fetch the auto_increment value and store that value in a session variable. The next script could then reference the data by the auto_increment value from the session variable. If you need data to go away, delete the offending record by the auto_increment value. Instead of creating and dropping tables, insert and delete data from a single table.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
$_SESSION['table'] is a random number assigned to the table as a name. I thought using temporary tables that they would be dropped after the connection closes.

This would be something that I'd like to sort out and not create a work around solution. I just don't understand why it would display correctly after pressing the back button and resubmitting the data. And also if I have another web page open that it works.

Reality is built on a foundation of dreams.
 
Table 'giftsongs.tester188' doesn't exist" is the error i get. but this only happens sometimes?!?!?

Reality is built on a foundation of dreams.
 
I tried using the same idea. The problem with what you are trying to do is that temporary tables are only linked to one mysql link. And just by pconnecting you don't guarantee that you get the same link when you call pconnect in the second page.

So far, I haven't found any way around this. I'm looking for a temporary table management system of some sort -- as I'd like to avoid recreating tables [that I use to handle reports ] every time especially when the underlying tables haven't changed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top