arianhojat Posted November 10, 2006 Share Posted November 10, 2006 Hello all,I am trying to get a temp table to work via php(5) and MYSQL(4.1); but i cant get it to work, not sure whats wrong, i run the queries via command client and they run fine ... here is my code:[code]$createTempString = 'CREATE TEMPORARY TABLE IF NOT EXISTS disaster_order';$createTempString .= '(';$createTempString .= ' empID int(5) NOT NULL,';$createTempString .= ' orderNum int(5) unsigned NOT NULL,';$createTempString .= ' PRIMARY KEY (empID,orderNum)';$createTempString .= ');';$result = mysql_query($createTempString) or die ("Error in query: $createTempString. ".mysql_error());//this array is really set via returning an unserialized database value which works fine in my code$empArray = array(46, 35, 40, 314, 393, 32, 59, 26, 54, 25, 51, 37, 58, 72, 76);$insertString = 'INSERT INTO disaster_order(empID, orderNum) VALUES';foreach($empArray as $key=>$empID)//0, 46 //1, 35{ $empOrder = $key; $insertString .= ' ('. $empID .', '. $empOrder .')'; if($key==(count($empArray)-1)) $insertString .= ';'; else if( count($empArray) > 1 ) $insertString .= ',';}$result = mysql_query($createTempString) or die ("Error in query: $insertString. ".mysql_error());//everything runs fine (no die() errors reported so i assume the temp table is created somewhere )$Query = "SELECT * FROM disaster_order";$result = mysql_query($Query) or die ("Error in query: $Query. ".mysql_error());//echo 'count='. mysql_num_rows( $result ); 0 reported backwhile($row=mysql_fetch_assoc($result)){ echo 'empID'='.$row['empID'] .'<br/>';}[/code]I assume I dont need to select some sort of predfined default named database where I would run my SELECT query against. like$db = "mysql_temp_storage";mysql_select_db($db) or die ("Unable to select database!");$Query = "SELECT * FROM disaster_order";I do however select a real database be4 the code I pasted above, just in case the temp table queries need to have some database open (like when it works in the command line client, i do have to USE some database just to run the query.)However my select statement in php isnt returning anything.PS the Queries my Php makes are:CREATE TEMPORARY TABLE IF NOT EXISTS disaster_order( empID int(5) NOT NULL, orderNum int(5) unsigned NOT NULL, PRIMARY KEY (empID,orderNum));INSERT INTO disaster_order(empID, orderNum) VALUES (46, 0), (35, 1), (40, 2), (314, 3), (393, 4), (32, 5), (59, 6), (26, 7), (54, 8), (25, 9), (51, 10), (37, 11), (58, 12), (72, 13), (76, 14); Quote Link to comment Share on other sites More sharing options...
fenway Posted November 10, 2006 Share Posted November 10, 2006 But you're sure the create is running properly? Like you can see this temp. table? Quote Link to comment Share on other sites More sharing options...
arianhojat Posted November 10, 2006 Author Share Posted November 10, 2006 how can i test to see if its there?i thought the select statement is only way to test if its really there.also none of the create/alter query statements that create/fill the table produced errors/die()'si just decided to use an actual permanent table to do it but i woulda prefered to try doing it via a temporary table since i never have tried it in php and would like it in my bag of tricks to use if i need it. Quote Link to comment Share on other sites More sharing options...
fenway Posted November 11, 2006 Share Posted November 11, 2006 SHOW TABLES should have an option for temporary. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.