pg_query to insert new point

View: New views
6 Messages — Rating Filter:   Alert me  

pg_query to insert new point

by André M :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
Hi everyone, first e-mail here.
I´m trying to insert a new point to a simple table called processos in a postgis database, using php, in a local server, with apache 2.2, php 5.2.12, postgre 8.3 and postgis 1.4.

here is the piece of code:

$sql = "INSERT INTO processos (id, the_geom) VALUES (1,(ST_PointFromText('POINT(-2 -62)',4291)))";
pg_query($con, $sql);




I can observe (with pg_affected_rows) there´s no new record.

Executing the same query directly in pgsql, with the same database user, returns a successfully result.

Any ideas on what´s wrong? I had never done any queries using php before, is there a way to see an error message when executing this kind of server-side request? tried firebug console but there´s nothing going on there...

Thanks a lot!

André Mendonça
Universidade Federal do Paraná
Curitiba - BR




Com o Novo Internet Explorer 8 suas abas se organizam por cor. Baixe agora, é grátis!
_______________________________________________
postgis-users mailing list
postgis-users@...
http://postgis.refractions.net/mailman/listinfo/postgis-users

Parent Message unknown Re: pg_query to insert new point

by Nicklas Avén :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

It might be that the webserver don't have authentication to access the database.
That is controlled from the file pg_hba.conf in the data-directory in the postgresql installation.
You should also check the file postgresql.conf in the same directory. At least if the webserver is on another machine than postgresql you have to change the line about listen_addresses so it looks like:
listen_addresses = '*'
if you want to let all ip-addresses in.
 
I don't know the details herer, but it might help you continue digging :-)
 
/Nicklas

2009-10-27 André Mendonça wrote:

Hi everyone, first e-mail here.
>I´m trying to insert a new point to a simple table called processos in a postgis database, using php, in a local server, with apache 2.2, php 5.2.12, postgre 8.3 and postgis 1.4.
>
>here is the piece of code:
>
>$sql = "INSERT INTO processos (id, the_geom) VALUES (1,(ST_PointFromText('POINT(-2 -62)',4291)))";
>pg_query($con, $sql);
>
>
>
>
>I can observe (with pg_affected_rows) there´s no new record.
>
>Executing the same query directly in pgsql, with the same database user, returns a successfully result.
>
>Any ideas on what´s wrong? I had never done any queries using php before, is there a way to see an error message when executing this kind of server-side request? tried firebug console but there´s nothing going on there...
>
>Thanks a lot!
>
>André Mendonça
>Universidade Federal do Paraná
>Curitiba - BR
>
>
>
>

Com o Novo Internet Explorer 8 suas abas se organizam por cor. Baixe agora, é grátis!
_______________________________________________
postgis-users mailing list
postgis-users@...
http://postgis.refractions.net/mailman/listinfo/postgis-users

Re: pg_query to insert new point

by Moen, Paul T. :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Try to look at the web server error logs as well.  On unix they are usually in /var/log/apache2/ or /var/log/httpd/ and named error_log or error.log.  I don't know where they are on windows systems, but maybe someone else could point you in the right location.  You could also use pg_last_error ($con); or pg_last_notice($con); to see the last error that would have been written to the log.  

Paul 


On Oct 27, 2009, at 2:33 AM, <nicklas.aven@...> <nicklas.aven@...> wrote:

It might be that the webserver don't have authentication to access the database.
That is controlled from the file pg_hba.conf in the data-directory in the postgresql installation.
You should also check the file postgresql.conf in the same directory. At least if the webserver is on another machine than postgresql you have to change the line about listen_addresses so it looks like:
listen_addresses = '*'
if you want to let all ip-addresses in.
 
I don't know the details herer, but it might help you continue digging :-)
 
/Nicklas

2009-10-27 André Mendonça wrote:

Hi everyone, first e-mail here.
>I´m trying to insert a new point to a simple table called processos in a postgis database, using php, in a local server, with apache 2.2, php 5.2.12, postgre 8.3 and postgis 1.4.
>
>here is the piece of code:
>
>$sql = "INSERT INTO processos (id, the_geom) VALUES (1,(ST_PointFromText('POINT(-2 -62)',4291)))";
>pg_query($con, $sql);
>
>
>
>
>I can observe (with pg_affected_rows) there´s no new record.
>
>Executing the same query directly in pgsql, with the same database user, returns a successfully result.
>
>Any ideas on what´s wrong? I had never done any queries using php before, is there a way to see an error message when executing this kind of server-side request? tried firebug console but there´s nothing going on there...
>
>Thanks a lot!
>
>André Mendonça
>Universidade Federal do Paraná
>Curitiba - BR
>
>
>
>

Com o Novo Internet Explorer 8 suas abas se organizam por cor. Baixe agora, é grátis!
_______________________________________________
postgis-users mailing list
postgis-users@...
http://postgis.refractions.net/mailman/listinfo/postgis-users


_______________________________________________
postgis-users mailing list
postgis-users@...
http://postgis.refractions.net/mailman/listinfo/postgis-users

Re: pg_query to insert new point

by P Kishor-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

2009/10/27 André Mendonça <andremalms@...>:

> Hi everyone, first e-mail here.
> I´m trying to insert a new point to a simple table called processos in a
> postgis database, using php, in a local server, with apache 2.2, php 5.2.12,
> postgre 8.3 and postgis 1.4.
>
> here is the piece of code:
>
> $sql = "INSERT INTO processos (id, the_geom) VALUES
> (1,(ST_PointFromText('POINT(-2 -62)',4291)))";
> pg_query($con, $sql);
>
>
>
>
> I can observe (with pg_affected_rows) there´s no new record.
>
> Executing the same query directly in pgsql, with the same database user,
> returns a successfully result.
>
> Any ideas on what´s wrong?

Perhaps your php db connection has auto commit turned off, so you have
to explicitly COMMIT after INSERT.


> I had never done any queries using php before, is
> there a way to see an error message when executing this kind of server-side
> request? tried firebug console but there´s nothing going on there...
>
> Thanks a lot!
>
> André Mendonça
> Universidade Federal do Paraná
> Curitiba - BR
>
>
>
> ________________________________
> Com o Novo Internet Explorer 8 suas abas se organizam por cor. Baixe agora,
> é grátis!
> _______________________________________________
> postgis-users mailing list
> postgis-users@...
> http://postgis.refractions.net/mailman/listinfo/postgis-users
>
>



--
Puneet Kishor http://www.punkish.org
Carbon Model http://carbonmodel.org
Charter Member, Open Source Geospatial Foundation http://www.osgeo.org
Science Commons Fellow, http://sciencecommons.org/about/whoweare/kishor
Nelson Institute, UW-Madison http://www.nelson.wisc.edu
-----------------------------------------------------------------------
Assertions are politics; backing up assertions with evidence is science
=======================================================================
Sent from Madison, WI, United States
_______________________________________________
postgis-users mailing list
postgis-users@...
http://postgis.refractions.net/mailman/listinfo/postgis-users

Parent Message unknown Re: pg_query to insert new point

by Tom Glancy :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

You are missing a semicolon to end the SQL statement. Try

$sql = "INSERT INTO processos (id, the_geom) VALUES
(1,(ST_PointFromText('POINT(-2 -62)',4291)));";
pg_query($con, $sql);


Regards,
Tom




---------------------------------------
Tom Glancy
Ecological Resources Division IT Manager

tom.glancy@...
651-259-5097

Minnesota Department of Natural Resources
500 Lafayette Road - Box 25
St. Paul, MN 55155-4025
---------------------------------------
>>> André Mendonça <andremalms@...> 10/27/09 2:03 AM >>>

Hi everyone, first e-mail here.
Ím trying to insert a new point to a simple table called processos in a
postgis database, using php, in a local server, with apache 2.2, php
5.2.12, postgre 8.3 and postgis 1.4.

here is the piece of code:

$sql = "INSERT INTO processos (id, the_geom) VALUES
(1,(ST_PointFromText('POINT(-2 -62)',4291)))";
pg_query($con, $sql);




I can observe (with pg_affected_rows) therés no new record.

Executing the same query directly in pgsql, with the same database user,
returns a successfully result.

Any ideas on what́s wrong? I had never done any queries using php
before, is there a way to see an error message when executing this kind
of server-side request? tried firebug console but therés nothing going
on there...

Thanks a lot!

André Mendonça
Universidade Federal do Paraná
Curitiba - BR


     
_________________________________________________________________
Você sabia que pode acessar o Messenger direto do seu Hotmail? Descubra
como!
http://www.microsoft.com/brasil/windows/windowslive/products/tutoriais.aspx
_______________________________________________
postgis-users mailing list
postgis-users@...
http://postgis.refractions.net/mailman/listinfo/postgis-users

Re: pg_query to insert new point

by Paragon Corporation-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

André ,
You could also output the error right on the php page by trapping it along the lines of
 
 
Personally - I tend to use an abstraction layer like PHP ADODB or PEAR.   It makes your code a bit more portable, and also much less to remember about the nuances of connecting
 
 
Hope that helps,
Regina

From: postgis-users-bounces@... [mailto:postgis-users-bounces@...] On Behalf Of Moen, Paul T.
Sent: Tuesday, October 27, 2009 9:18 AM
To: PostGIS Users Discussion
Subject: Re: [postgis-users] pg_query to insert new point

Try to look at the web server error logs as well.  On unix they are usually in /var/log/apache2/ or /var/log/httpd/ and named error_log or error.log.  I don't know where they are on windows systems, but maybe someone else could point you in the right location.  You could also use pg_last_error ($con); or pg_last_notice($con); to see the last error that would have been written to the log.  

Paul 


On Oct 27, 2009, at 2:33 AM, <nicklas.aven@...> <nicklas.aven@...> wrote:

It might be that the webserver don't have authentication to access the database.
That is controlled from the file pg_hba.conf in the data-directory in the postgresql installation.
You should also check the file postgresql.conf in the same directory. At least if the webserver is on another machine than postgresql you have to change the line about listen_addresses so it looks like:
listen_addresses = '*'
if you want to let all ip-addresses in.
 
I don't know the details herer, but it might help you continue digging :-)
 
/Nicklas

2009-10-27 André Mendonça wrote:

Hi everyone, first e-mail here.

>I´m trying to insert a new point to a simple table called processos in a postgis database, using php, in a local server, with apache 2.2, php 5.2.12, postgre 8.3 and postgis 1.4.
>
>here is the piece of code:
>
>$sql = "INSERT INTO processos (id, the_geom) VALUES (1,(ST_PointFromText('POINT(-2 -62)',4291)))";
>pg_query($con, $sql);
>
>
>
>
>I can observe (with pg_affected_rows) there´s no new record.
>
>Executing the same query directly in pgsql, with the same database user, returns a successfully result.
>
>Any ideas on what´s wrong? I had never done any queries using php before, is there a way to see an error message when executing this kind of server-side request? tried firebug console but there´s nothing going on there...
>
>Thanks a lot!
>
>André Mendonça
>Universidade Federal do Paraná
>Curitiba - BR
>
>
>
>

Com o Novo Internet Explorer 8 suas abas se organizam por cor. Baixe agora, é grátis!
_______________________________________________
postgis-users mailing list
postgis-users@...
http://postgis.refractions.net/mailman/listinfo/postgis-users



__________ Information from ESET NOD32 Antivirus, version of virus signature database 4547 (20091027) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

_______________________________________________
postgis-users mailing list
postgis-users@...
http://postgis.refractions.net/mailman/listinfo/postgis-users