php function for getting a mysql table stucture

Discussion in 'PHP' started by stephan2307, Mar 29, 2010.

  1. #1
    Hi

    is there a php function which creates the SQL for creating a table from an existing table?
    I mean similar to the phpmyadmin export function.

    Any idea anyone?
     
    stephan2307, Mar 29, 2010 IP
  2. meloncreative

    meloncreative Peon

    Messages:
    37
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Do you mean basically copy a table structure only?

    CREATE TABLE tablename LIKE copythisone
    Code (markup):
     
    meloncreative, Mar 29, 2010 IP
  3. stephan2307

    stephan2307 Well-Known Member

    Messages:
    1,277
    Likes Received:
    33
    Best Answers:
    7
    Trophy Points:
    150
    #3
    Not quite. I want the sql query as a string so I can do something else with it.
     
    stephan2307, Mar 29, 2010 IP
  4. stephan2307

    stephan2307 Well-Known Member

    Messages:
    1,277
    Likes Received:
    33
    Best Answers:
    7
    Trophy Points:
    150
    #4
    What I am doing is basically write a web based application where you can connect to 2 database servers at the same time. You will be able to see all the databases and all tables and then you can copy a table or a database from one server to another without having to download anything.
     
    stephan2307, Mar 29, 2010 IP
  5. meloncreative

    meloncreative Peon

    Messages:
    37
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    $q = "CREATE TABLE tablename LIKE copythisone";
    Code (markup):
    :p

    Erm there arent really any php functions for what you are talking about, you just need to figure it out in SQL, or you can pass mysql_query() a second parameter to say which specified which database handle to use

    $handle_db1 = mysql_connect("serverone","userone","passone");
    $handle_db2 = mysql_connect("servertwo","usertwo","passtwo");
    
    // give each handle it's own database to work with, permanently.
    mysql_select_db("tableone",$handle_db1);
    mysql_select_db("tabletwo",$handle_db2);
    
    $result1 = mysql_query($queryone, $handle_db1);
    $result2 = mysql_query($querytwo, $handle_db2);
    Code (markup):
     
    meloncreative, Mar 29, 2010 IP
  6. stephan2307

    stephan2307 Well-Known Member

    Messages:
    1,277
    Likes Received:
    33
    Best Answers:
    7
    Trophy Points:
    150
    #6
    Yeah I already got all that. I so far that I can browse both servers databases and select a table to copy to another database. Just need the creation query.

    Might have a look how phpmyadmin does it.
     
    stephan2307, Mar 30, 2010 IP
  7. stOK

    stOK Active Member

    Messages:
    114
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #7
    SHOW CREATE TABLE tbl_name
     
    stOK, Mar 30, 2010 IP
  8. stephan2307

    stephan2307 Well-Known Member

    Messages:
    1,277
    Likes Received:
    33
    Best Answers:
    7
    Trophy Points:
    150
    #8
    That's brilliant.

    thanks.

    I start to love SHOW.
     
    stephan2307, Mar 30, 2010 IP