How To Create a New Table

Q

How To Create a New Table? - MySQL FAQs - Managing Tables and Running Queries with PHP Scripts

✍: FYIcenter.com

A

If you want to create a table, you can run the CREATE TABLE statement as shown in the following sample script:

<?php
  include "mysql_connection.php";

  $sql = "CREATE TABLE fyi_links ("
      . " id INTEGER NOT NULL" 
      . ", url VARCHAR(80) NOT NULL"
      . ", notes VARCHAR(1024)"
      . ", counts INTEGER"
      . ", time TIMESTAMP DEFAULT CURRENT_TIMESTAMP()"
      . ")";
  if (mysql_query($sql, $con)) {
    print("Table fyi_links created.\n");
  } else {
    print("Table creation failed with error:\n");
    print(mysql_errno($con).": ".mysql_error($con)."\n");
  }

  mysql_close($con); 
?>

Remember that mysql_query() returns TRUE/FALSE on CREATE statements. If you run this script, you will get something like this:

Table fyi_links created.

2007-05-10, 4469👍, 0💬