#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2001
    Location
    uk
    Posts
    1
    Rep Power
    0

    Unhappy Creating new table in PostgreSQL


    I am a total beginner and am trying to add a new table to the database. This is what I am using, it was originally MYSQL code. where am I going wrong?

    I would be grateful for any help.

    Cheers
    Will

    <?

    $db_name = "db_name_here";

    $db=pg_pconnect("host="" port="" dbname="" user="" password=""") or die("dead");


    // build the query

    $sql = "CREATE TABLE $table_name (";

    for ($i = 0; $i < count($field_name); $i++) {

    $sql .= "$field_name[$i] $field_type[$i]";

    if ($field_length[$i] != "") {
    $sql .= " ($field_length[$i]),";
    } else {
    $sql .= ",";
    }
    }

    $sql = substr($sql, 0, -1);

    $sql .= ")";


    // execute the query

    $result = pg_exec($sql,$db)
    or die("Couldn't execute query.");

    if ($result) {
    $msg = "<P>$table_name has been created!</p>";
    }


    ?>

    <HTML>
    <HEAD>
    <TITLE>Create a Database Table: Step 3</TITLE>
    </HEAD>
    <BODY>

    <h1>Adding table to <? echo "$db_name"; ?>...</h1>

    <? echo "$msg"; ?>


    </BODY>
    </HTML>
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2001
    Location
    Johannesburg, South Africa
    Posts
    6
    Rep Power
    0
    Willhives:

    PostgreSQL and MySQL table creation are as compatible as The Queen of England and Brittainy Spears...... so I found out!!!

    Example:

    MySQL: id tinyint DEFAULT '0' NOT NULL auto_increment

    PgSQL: id int2 serial

    MySQL types that will give you grief under PostgreSQL:

    tinyint, tinytext, smalltext etc

    Get a good PostgreSql reference a good editor and happy editting!!!

    When connecting to your PostgreSQL database try:
    $db=pg_pconnect("dbname=$my_db_name user=$user_name");
    Last edited by dube; August 10th, 2001 at 11:01 AM.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2000
    Location
    jakarta
    Posts
    11
    Rep Power
    0
    Willhives:

    $result = pg_exec($sql,$db) or die("Couldn't execute query.");
    try use pg_exec($db,$sql);

    this will answer you

IMN logo majestic logo threadwatch logo seochat tools logo