|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
|||
|
|||
|
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. |
|
#3
|
|||
|
|||
|
Quote:
try use pg_exec($db,$sql); this will answer you ![]() |
![]() |
| Viewing: Dev Shed Forums > Databases > PostgreSQL Help > Creating new table in PostgreSQL |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|