Jump to content

[SOLVED] Temporary tables on php


wsantos

Recommended Posts

Im trying to implement temporary table on one of my applications.  I run this queries in succession directly from mysql.

 

mysql>DROP TEMPORARY TABLE IF EXISTS tmp_tbl1;
mysql>CREATE TEMPORARY TABLE tmp_tbl1 SELECT uid,src FROM tblMain WHERE start BETWEEN '2007-11-16 00:00:00' AND '2007-11-16 23:59:59';
mysql>SELECT callid FROM lookup_callid JOIN tmp_tbl1 ON lookup_callid.uid=tmp_tbl1.uid;

 

The above gave me the result that I expected.  However, via php

 

$qry1 = "DROP TEMPORARY TABLE IF EXISTS tmp_tbl1";
$qry2 = "CREATE TEMPORARY TABLE tmp_tbl1 SELECT uid,src FROM tblMain WHERE start BETWEEN '2007-11-16 00:00:00' AND '2007-11-16 23:59:59'";
$qry3 = "SELECT callid FROM lookup_callid JOIN tmp_tbl1 ON lookup_callid.uid=tmp_tbl1.uid";

mysql_query($qry1,$con)
mysql_query($qry2,$con)
$result = mysql_query($qry3,$con)

while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
    $daRec[] = $row;
}
mysql_free_result($result);
print_r($daRec);

 

That returned an empty array.

Link to comment
https://forums.phpfreaks.com/topic/77745-solved-temporary-tables-on-php/
Share on other sites

well first off php doesn't have temporary table (mysql does)

 

That answers the question. Any way around this? Perhaps treating an array as a table and doing a query on that?

As for your second point, This is just the first part of 7 joins from a very big db with many processes running in it.  Usually with intervals of 2 minutes. Using joins in this case is not our option.

 

Thanks for the help though.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.