1,105,636 Community Members

Problem Creating a Temporary Table in MySQL

Member Avatar
johnnycho
Newbie Poster
14 posts since Jan 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

I'm new to using Temporary Tables in PHP/MySQL. I wrote a very simple test script just to see if it would work, but the SELECT query is giving me a mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given error on the last line, and I'm not sure why.

$dbc is the database connection, which I'm not having any trouble with. Also, this is obviously on MySQL 5 using mysqli queries.

Any help would be greatly appreciated.

$query_createtemptable = "CREATE TEMPORARY TABLE everything (everything_id INT UNSIGNED NOT NULL AUTO_INCREMENT, movietitle VARCHAR(255), person_name VARCHAR(255))";
$result_createtemptable = mysqli_query($dbc, $query_createtemptable);
		
$query_insertintotable = "INSERT INTO everything (movietitle, person_name) VALUES ('The Shawshank Redemption', 'Tim Robbins')";
$result_insertintotable = mysqli_query($dbc, $query_insertintotable);
		
$query_selecttemptable = "SELECT movietitle, person_name FROM everything";
$result_selecttemptable = mysqli_query($dbc, $query_selecttemptable);

$row_selecttemptable = mysqli_fetch_array($result_selecttemptable);

If I echo $row_selecttemptable from above, shouldn't it give me 'The Shawshank Redemption'?

Member Avatar
navdeep7489
Newbie Poster
8 posts since Jul 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

Use while loop,it may be due to retreival of multiple values from table ,coode is:

while($row_selecttemptable = mysqli_fetch_array($result_selecttemptable))
{
echo $row_selecttemptable;
}

Member Avatar
johnnycho
Newbie Poster
14 posts since Jan 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Thanks for your suggestion, navdeep7489. Unfortunately it didn't work.

I should also mention that I have the CREATE TEMPORARY TABLE privilege enabled, so that's not the issue either.

Member Avatar
johnnycho
Newbie Poster
14 posts since Jan 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

The awesome support staff at ICDSoft.com figured out what the problem was, and as HAL 9000 would have gleefully (if monotonally) said, "It was attributable to human error."

My CREATE query needed to identify the AUTO-INCREMENT column as the PRIMARY KEY. So it should have read:

$query_createtemptable = "CREATE TEMPORARY TABLE everything (everything_id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, movietitle VARCHAR(255), person_name VARCHAR(255))";
Question Answered as of 3 Years Ago by navdeep7489
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: