working with temporary tables in Joomla 2.5 - mysql

I am trying to use MySql temporary tables with my joomla site.
the problem is that whenever I query about the content of the table I get an empty result (except when using select statement in the same function where I create the table).
My questions are:
everytime I use $db = JFactory::getDBO() - do I create a new DB connection?
if so - how can I use temporary files?
if not - why don't I get the data of the temp table?
How can I create a temporary table that will remain until the user logs out?

You cannot use temporary tables like this, read the docs on temporary tables in MySQL here. The table will be deleted on each session, which will probably be each page load, possibly sooner, depending on how this is handled throughout Joomla.
If you want your temporary table to persist, you need to create normal table, not a temporary table...

Related

How to synchronize view table to manual temporary table?

I have tables in database that consist of so many data records. I made view tables because I joined the tables. Then, when I tried to open the view tables, the time took so long because the tables had many data. So, I decided to make temporary table like this:
CREATE TABLE temp_ AS (SELECT * FROM view)
then, I want to synchronize the view and temporary table. As the example, when I tried to update the view table, then we're able to know that the temporary table has to change too because the temporary is synchronized with the view table. Maybe, it can be solved when the view's updated time > generated time than we have to update the table
I have table like this
I manually inserted the data records to both of that table. What may I do to synchronize them? Thanks in advance

Can't drop table after creating table with wrong engine

I'm trying to drop a table containing several hundred thousand column-based records. Normally when creating the database I use a column-based engine (infinidb) but in this case I forgot to include the ENGINE statement. So the database is pretty much unusable for my needs. Now I have a database full of tables that are taking forever to drop (it's been two hours and nothing has happened). I tried the ALTER TABLE table ENGINE=INFINIDB command but again, it's taking forever (see above re: two hours). EDIT: The first command I tried was DROP TABLE. It hung with every single table. Then I tried the ALTER command in case that was faster for some reason, but it wasn't.
Is there another way to get rid of this database? E.g. manually going into the /mysql/ directory and deleting the database? I guess I could just rename it and leave it, but I'd rather get rid of it entirely so it's not taking up space.
First of all you said Can't drop table. But in post you mentioned ALTER TABLE table ENGINE=INFINIDB.
But DROP != ALTER it is two different things.
So you can do following:
CREATE new table with same structure but engine you need.
copy(UPDATE) data from old table to the one you just created.
DROP old table.
RENAMErename new one to old name
It turned out that another process (a website) was using this database and had a couple of queries that got 'stuck' in the SQL server and caused the table to hang due to the database using the wrong engine, which I'm assuming was InnoDB since I didn't specify an engine when I initially used the "CREATE TABLE table1 AS SELECT * FROM table2" command. We finally managed to wipe the database and start over. Thanks for your help.

How to replace mysql table with updated one without dropping table

I am using mysql table on my website where I update table frequently. Instead of altering table on remote server I do it on localhost and then upload it. While uploading I drop table first which causes problem for website user for a moment.
Is there anyway to replace table without dropping.
You can upload the table with a temporary name. After the upload completes you can drop the original and rename the temporary.
In this way the downtime would be very limited.

MySql TABLE data type

MS SQL Server has a TABLE data type which can be used in stored procedures,
Does anybody know if MySQL has an equivalent data type?
I've had a look over the docs but can't seem to find anything, so I presume it doesn't exist, but perhaps somebody has created a workaround
Neil,
MySQL has no such data type and I believe it is good that it doesn't. To achieve similar results, use CREATE TEMPORARY TABLE construction. Name clashes are avoided by having per connection temporary tables:
A TEMPORARY table is visible only to the current connection, and is dropped automatically when the connection is closed. This means that two different connections can use the same temporary table name without conflicting with each other or with an existing non-TEMPORARY table of the same name. (The existing table is hidden until the temporary table is dropped.)
Hope it helps.

MySQL: what is a temporary table?

What is the purpose of a temporary table like in the following statement? How is it different than a regular table?
CREATE TEMPORARY TABLE tmptable
SELECT A.* FROM batchinfo_2009 AS A, calibration_2009 AS B
WHERE A.reporttime LIKE '%2010%'
AND A.rowid = B.rowid;
Temp tables are kept only for the duration of your session with the sever. Once the connection's severed for any reason, the table's automatically dropped. They're also only visible to the current user, so multiple users can use the same temporary table name without conflict.
Temporary table ceases to exist when connection is closed. So, its purpose is for instance to hold temporary result set that has to be worked on, before it will be used.
Temporary tables are mostly used to store query results that need further processing, for instance if the result needs to be queried or refined again or is going to be used at different occasions by your application. Usually the data stored in a temporary database contains information from several regular tables (like in your example).
Temporary tables are deleted automatically when the current database session is terminated.
Support for temporary tables exists to allow procedural paradigms in a set-based 4GL, either because the coder has not switched their 3GL mindset to the new paradigm or to work around a performance or syntax issue (perceived or otherwise).