0

Hi guys....ammm...I created a table in one function and then used it in another function. The temporary table is created this way:

$tmpTable = "tmpTable";
myCreateTable($intHandle,$tmpTable,$schoolYr,$semester);       



CREATE TEMPORARY  TABLE $tmpTable  type = heap
SELECT Payment.No FROM (Payment INNER JOIN Othr ON Payment.Autokey = Othr.key)

I am passing the table name this way:

myAnotherFuction($intHandle,$tmpTable);                      
myAnotherFunction2($intHandle,$tmpTable);

...using inner join to link it to another table.

SELECT Main.Gender FROM Main INNER JOIN $tmpTable ON Main.No = $tmpTable.No

now my problem is that the table did not exist...I couldn't figure it out whats going on with this when I've createdd the temporary table before hand but still it did not exist?

3
Contributors
2
Replies
16
Views
4 Years
Discussion Span
Last Post by diafol
1

Hard to say from just these function calls, but a temporary table is dropped when the connection drops.

0

Agree with pritaeas wrt to connection drop.

http://www.tutorialspoint.com/mysql/mysql-temporary-tables.htm

Placing this (from the example above) into my mySQL client...

CREATE TEMPORARY TABLE SalesSummary (
    product_name VARCHAR(50) NOT NULL, 
    total_sales DECIMAL(12,2) NOT NULL DEFAULT 0.00,
    avg_unit_price DECIMAL(7,2) NOT NULL DEFAULT 0.00,
    total_units_sold INT UNSIGNED NOT NULL DEFAULT 0);

INSERT INTO SalesSummary(product_name, total_sales, avg_unit_price, total_units_sold) VALUES ('cucumber', 100.25, 90, 2);   

SELECT * FROM SalesSummary;

Worked fine for me. Similarly...

$link = mysql_connect('localhost', 'root', '');
if (!$link) {
    die('Not connected : ' . mysql_error());
}

// make foo the current db
$db_selected = mysql_select_db('dw2', $link);
if (!$db_selected) {
    die ('Can\'t use dw2 : ' . mysql_error());
}

mysql_query("CREATE TEMPORARY TABLE SalesSummary (
    product_name VARCHAR(50) NOT NULL, 
    total_sales DECIMAL(12,2) NOT NULL DEFAULT 0.00,
    avg_unit_price DECIMAL(7,2) NOT NULL DEFAULT 0.00,
    total_units_sold INT UNSIGNED NOT NULL DEFAULT 0)");

mysql_query("INSERT INTO SalesSummary(product_name, total_sales, avg_unit_price, total_units_sold) VALUES ('cucumber', 100.25, 90, 2)");    

$r= mysql_query("SELECT * FROM SalesSummary");

while($d = mysql_fetch_assoc($r)){
    echo $d['product_name'];
}

Worked as expected.

Edited by diafol

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.