Welcome Guest, Not a member yet? Register   Sign In
can temporary tables be used in PHP?
#11

(This post was last modified: 09-29-2022, 12:18 AM by JustJohnQ.)

https://stackoverflow.com/questions/4111...connection

Some more testing:

PHP Code:
$sql "CREATE TEMPORARY TABLE BC_PR_list_temp(taxyear VARCHAR(10))";
$this->db->query($sql);

$sql "INSERT INTO BC_PR_list_temp (taxyear) VALUES (1984)";
$this->db->query($sql);

$sql "SELECT * FROM BC_PR_list_temp";
$result $this->db->query ($sql);
$data $result->result ();
print_r($data); 

This works fine within a function, so the temp table is created. As mentioned earlier, it will be deleted once the db session is closed.

PHP Code:
$this->db->table_exists('BC_PR_list_temp'


table_exists() doesn't work for temporary tables, the result is always false. As a matter of fact, it is not easy to check if a temporary table exists using SQL.

Conclusion: it is not a CI problem, but a MySQL limitation when working with temporary tables. I suggest you find a way to work with normal tables.
Reply


Messages In This Thread
RE: can temporary tables be used in PHP? - by JustJohnQ - 09-28-2022, 01:02 PM



Theme © iAndrew 2016 - Forum software by © MyBB