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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.