Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 9 of 9
  1. #1
    Senior Member iphong's Avatar
    Join Date
    Mar 2003
    Location
    Arlington, VA
    Posts
    751
    Member #
    916
    How do i creat a MYSQL table using php? thanks
    Vu Tuan Phong
    iPhongDesign

    http://iphong.com
    http://adstudio1.com

  2.  

  3. #2
    Senior Member filburt1's Avatar
    Join Date
    Jul 2002
    Location
    Maryland, US
    Posts
    11,774
    Member #
    3
    Liked
    21 times
    Just run a query:
    PHP Code:
    mysql_query("CREATE TABLE whatever (somefield TEXT NULL)"); 
    ...for example.
    filburt1, Web Design Forums.net founder
    Site of the Month contest: submit your site or vote for the winner!

  4. #3
    Senior Member skrlin's Avatar
    Join Date
    Apr 2003
    Location
    Illinois
    Posts
    562
    Member #
    1063
    Maybe this will help, its some code I took from a PHP book I have:


    PHP Code:
    <?php

      
    // form your mysql query that creates the table
      
    $sql "CREATE TABLE tableName (fieldName TEXT NULL)";

     
    // create a connection to your database
     // substitute your hostname, username and password
     
    $connection mysql_connect("localhost","user","pass") or die("No connection...");

     
    // select database
     // substitute your database name
     
    $db mysql_select_db("secretDB",$connection) or die("Problem selecting database.)";

     
    // execute SQL query and get result
     
    $sql_result mysql_query($sql,$connection) or die("Execution error.");

     if (!
    $sql_result) {
        echo 
    "<P>Table creation error...";
     } else {
        echo 
    "<P>tableName has been created!";
     }

    ?>
    - Brian

  5. #4
    Senior Member Brak's Avatar
    Join Date
    Apr 2003
    Location
    San Francisco, CA
    Posts
    3,413
    Member #
    1217
    Liked
    2 times
    Or... http://www.phpmyadmin.net/ takes about 10 seconds to install and comes with a nice gui for lazy typers like me
    Kyle Neath: Rockstar extraordinare
    The blog | The poetry site | The Spore site

  6. #5
    Senior Member iphong's Avatar
    Join Date
    Mar 2003
    Location
    Arlington, VA
    Posts
    751
    Member #
    916
    Ok thank guys!
    Vu Tuan Phong
    iPhongDesign

    http://iphong.com
    http://adstudio1.com

  7. #6
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    You should never have to create a table programmatically, anyway. If you have to modify your database structure for your application to work, it's designed wrong (unless it's for archiving data in archive tables).

  8. #7
    Senior Member Brak's Avatar
    Join Date
    Apr 2003
    Location
    San Francisco, CA
    Posts
    3,413
    Member #
    1217
    Liked
    2 times
    What about software like phBB, vBullitin, phpNuke, etc... there's plenty of reasoning for creating tables
    Kyle Neath: Rockstar extraordinare
    The blog | The poetry site | The Spore site

  9. #8
    Senior Member filburt1's Avatar
    Join Date
    Jul 2002
    Location
    Maryland, US
    Posts
    11,774
    Member #
    3
    Liked
    21 times
    Those never create tables during normal operation. vBulletin alters tables, and even then I think only when adding custom profile fields.

    You should still know how to do it if you're writing an install script or something like phpMyAdmin.
    filburt1, Web Design Forums.net founder
    Site of the Month contest: submit your site or vote for the winner!

  10. #9
    Senior Member Brak's Avatar
    Join Date
    Apr 2003
    Location
    San Francisco, CA
    Posts
    3,413
    Member #
    1217
    Liked
    2 times
    Well yes, I was referring to the install script.
    Kyle Neath: Rockstar extraordinare
    The blog | The poetry site | The Spore site


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 03:03 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com