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'?

Recommended Answers

All 3 Replies

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;

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.

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))";
Be a part of the DaniWeb community

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