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?

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

Member Avatar for diafol

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.