Jump to content

Error inserting values into a row in postgreSQL throught php


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);";

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 topic is now archived and is closed to further replies.

  • 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.