
August 7th, 2001, 11:59 AM
|
|
Junior Member
|
|
Join Date: Aug 2001
Location: uk
Posts: 1
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
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>
|