Jump to content

Error inserting values into a row in postgreSQL throught php


JotaTR

Recommended Posts

Hi there.

 

I am new at php and postegresql, I have installed postegreSQL 9.3 and wampserver 2.3. I have already enable the postgreSQL extensions.

I am trying to acess a database with the name db where is already created a 3 collumn table (text,text,double). I want to insert a value into it using a php code.

 

The php code that i have is this:

$dbconn = pg_connect("host=localhost port=5432 dbname=postgres
                      user=postgres password=passss")
          or die('It was not possible to connect: ' . pg_last_error());
echo 'Connected: ', pg_dbname($dbconn);

$query = "INSERT INTO bd(
            dia, hora, voltagem)
    VALUES ('18-9-2013', '17:32:37', 302);";
$linha=pg_query($dbconn,$query);
pg_close($dbconn);

When opening the file in the browser i get:

 

Connected: postgres

( ! ) Warning: pg_query(): Query failed: ERROR: relation "bd" does not exist LINE 1: INSERT INTO bd( ^ in C:\wamp\www\connectDB.php on line 12 Call Stack # Time Memory Function Location 1 0.0005 246472 {main}( ) ..\connectDB.php:0 2 0.0354 247848 pg_query ( ) ..\connectDB.php:12

 

What am i doing wrong? i dont get it. Does anyone can give me a little help?

Thanks in advance

Link to comment
Share on other sites

  • 11 months later...

Just a guess as I'm new to PostgreSQL myself, but you might need a space inbetween the table name and the opening parenthesis. I'm thinking that because there is a new line after the opening parenthesis without a space between it and the table name PostgreSQL is assuming the table name is "bd(" and not "bd".

 

At least that's the impression I got after reading http://www.postgresql.org/docs/9.3/static/sql-syntax-lexical.html

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.