PostgreSQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesPostgreSQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 7th, 2001, 11:59 AM
willhives willhives is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2001
Location: uk
Posts: 1 willhives User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation 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>

Reply With Quote
  #2  
Old August 10th, 2001, 10:49 AM
dube dube is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2001
Location: Johannesburg, South Africa
Posts: 6 dube User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation 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.

Reply With Quote
  #3  
Old August 20th, 2001, 11:45 PM
bambanghendra bambanghendra is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2000
Location: jakarta
Posts: 11 bambanghendra User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to bambanghendra
Quote:
Willhives:

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


try use pg_exec($db,$sql);

this will answer you

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesPostgreSQL Help > Creating new table in PostgreSQL


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway