SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot DarkMonkey's Avatar
    Join Date
    Apr 2001
    Location
    uk
    Posts
    170
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I really want to make a copy of one of my tables. I dont suppose it's relivent, but I'll explain why anyway. My db design wasn't so good when I made my original site, I've now thought of better ways to do stuff, so I'd like to change the tables's, however I dont want to take my site down, I'd rather let people surf it and work on the new system behind the scenes, I can't do that if my changes to the articles database are affecting the site. If I had a copy I could fix it all up then just upload the new scripts.

    Basically, I'd like to copy all the contents of the articles table into say a new table 'articles2' ... I dont have comand line access. Is there a way to do this? I'd reallly appreciate it.

  2. #2
    SitePoint Enthusiast
    Join Date
    Feb 2001
    Posts
    58
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is my run at it.

    PHP Code:
    //database connection info here

    $sql "Select * from Table";
    $res mysql_query($sql);

    while (
    $row msyql_fetch_array($res)) {

      
    $sql "Insert into Table2 (field1, field2, etc) values ('$row[field1]', '$row[field2]', etc)";
      
    $res mysql_query($sql);


    Marty H.

  3. #3
    SitePoint Zealot DarkMonkey's Avatar
    Join Date
    Apr 2001
    Location
    uk
    Posts
    170
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, I'll use that method, if anybody knows of a built in mysql function to copy a table, however, that would be ideal.

    Thanks again, Marty.

  4. #4
    SitePoint Member
    Join Date
    Feb 2001
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you're using MySQL 3.23, check out the new CREATE TABLE option:

    CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name [(create_definition,...)]
    [table_options] [select_statement]

    ...notice the select_statement option at the end. I haven't used this personally, as I just use mysqldump from the command line. It should work for your purposes, though. Use create table to create a new table with the same structure as the old, and add a "select * from articles" to the end of the create table statement.

    Good luck!
    Travis Burnside
    travis@qwk.net

    Free monitoring for your web site - http://www.qwkmon.com


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •