SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict CeleronXL's Avatar
    Join Date
    Dec 2002
    Location
    United States of America
    Posts
    349
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Renaming MySQL Tables..

    Quick question, is this query valid to run in PHP?

    ALTER TABLE oldname RENAME newname;

    To rename a table? So far everywhere I look says to run that in the MySQL monitor.
    So hold me when I'm here
    Right me when I'm wrong
    Hold me when I'm scared
    Love me when I'm gone.

  2. #2
    SitePoint Zealot
    Join Date
    Jul 2003
    Location
    Palo Alto
    Posts
    179
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Never tried it, but anything you can run in mysql you should be able to run using PHP's mysql_query().

  3. #3
    SitePoint Addict CeleronXL's Avatar
    Join Date
    Dec 2002
    Location
    United States of America
    Posts
    349
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, except sometimes they do it differently. Like

    USE database;

    And

    mysql_select_db('database');

    So yeah, I was just wondering..
    So hold me when I'm here
    Right me when I'm wrong
    Hold me when I'm scared
    Love me when I'm gone.

  4. #4
    SitePoint Zealot
    Join Date
    Jul 2003
    Location
    Palo Alto
    Posts
    179
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah, I see. PHP's MySQL module doesn't have any built-in functions for renaming tables, so you'll want to use mysql_query() instead. You could probably use mysql_query() to select a database as well, but of course there's little reason to do so since the API provides a method for you.

  5. #5
    SitePoint Addict CeleronXL's Avatar
    Join Date
    Dec 2002
    Location
    United States of America
    Posts
    349
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Right, so

    $DB->query("ALTER TABLE oldname RENAME newname");

    ought to work, aye?
    So hold me when I'm here
    Right me when I'm wrong
    Hold me when I'm scared
    Love me when I'm gone.


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
  •