Copy

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Straterra
Forum Regular
Posts: 527
Joined: Mon Nov 24, 2003 8:46 am
Location: Indianapolis, Indiana
Contact:

Copy

Post by Straterra »

How would I copy everything from one table to another?
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

Post by AVATAr »

create a table: copy_table
and then:
SELECT * INTO copy_table FROM table
Straterra
Forum Regular
Posts: 527
Joined: Mon Nov 24, 2003 8:46 am
Location: Indianapolis, Indiana
Contact:

Post by Straterra »

Code: Select all

sqlite_query($db, "SELECT * INTO clanprofile2 FROM clanprofile");
That doesn't seem to work at all... I get this message

Warning: sqlite_query(): near "INTO": syntax error in c:\ftp\users\straterra\eck\cgi-bin\full1.php on line 32
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

Post by AVATAr »

did you create the table clanprofile2?
Straterra
Forum Regular
Posts: 527
Joined: Mon Nov 24, 2003 8:46 am
Location: Indianapolis, Indiana
Contact:

Post by Straterra »

Yes, the table is created.
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

Post by AVATAr »

Maybe its not supported by sql-lite.

check this:

http://www.w3schools.com/sql/sql_select_into.asp
Straterra
Forum Regular
Posts: 527
Joined: Mon Nov 24, 2003 8:46 am
Location: Indianapolis, Indiana
Contact:

Post by Straterra »

http://www.hwaci.com/sw/sqlite/omitted.html

That website says to add collumns, you have to copy the current into a temporary table...(ALTER TABLE To change a table you have to delete it (saving its contents to a temporary table) and recreate it from scratch. ) I wanted to copy so that I could add collumns. But, how can I move the current table to a new table when SQLite doesn't support the fricking SELECT * INTO clanprofile2 FROM clanprofile thing...
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

Post by AVATAr »

good point..

1- make a php script.. with select in one table and insert in other
2- why are you using sqllite?
Straterra
Forum Regular
Posts: 527
Joined: Mon Nov 24, 2003 8:46 am
Location: Indianapolis, Indiana
Contact:

Post by Straterra »

AVATAr wrote:good point..

1- make a php script.. with select in one table and insert in other
2- why are you using sqllite?
I don't understand what you mean with your first point. But the reason I use SQLite is because it's both smaller and faster than MySQL. Also, it doesn't eat system resources, like MySQL does. I have an older server, so I found SQLite to be quite friendly. This is the only problem I have ever had with SQLite.
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

Post by AVATAr »

1- make a php script with a select * and then make a foreach in that resource and insert those values in the new table.

How many records?
Straterra
Forum Regular
Posts: 527
Joined: Mon Nov 24, 2003 8:46 am
Location: Indianapolis, Indiana
Contact:

Post by Straterra »

God..that could take a while. I suck at foreach's...Lemme try to write something really quickly. The table has maybe 10 rows..and perhaps 15 collumns.
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

Post by AVATAr »

10 rows... it will be very quick!
Straterra
Forum Regular
Posts: 527
Joined: Mon Nov 24, 2003 8:46 am
Location: Indianapolis, Indiana
Contact:

Post by Straterra »

Since I am such a newbie..could you tell me if I am on the right path?

Code: Select all

$result = (sqlite_query($db, "SELECT * from clanprofile"));
foreach ($result as $rst2) {
Straterra
Forum Regular
Posts: 527
Joined: Mon Nov 24, 2003 8:46 am
Location: Indianapolis, Indiana
Contact:

Post by Straterra »

I currently have this

Code: Select all

$result = (sqlite_query($db, "SELECT * from clanprofile"));
$row=sqlite_fetch_array($result);
foreach ($row as $rst2) {
echo $rst2;
}

Weird..It only prints like one row..What did I do wrong?
Straterra
Forum Regular
Posts: 527
Joined: Mon Nov 24, 2003 8:46 am
Location: Indianapolis, Indiana
Contact:

Post by Straterra »

I think I have it figured out now. Thank you SO MUCH for your help. After I get done, I will write a tutorial on how to do it!
Post Reply