Steve_C (3) [Avatar] Offline
#1
Hi,

I'm successfully running my functions in pgAdmin3 that use PostGIS functions. When I run from PHP using pg_query they error saying the functions (eg ST_MakePoint) do not exist (all other functions I have built, and sql statements built directly in PHP, run ok).

Do I need to copy PostGIS files somewhere for PHP to find? Or do I have to make an entry in PHP ini file to point to PostGIS files?

My environment is Mac OS 10.6.8. I obtained Postgresql/PostGIS via EnterpriseDB and I am using Postgresql v8.4.9. 'SELECT postgis_full_version();' run in pgAdmin3 displays ""POSTGIS="1.4.2" GEOS="3.2.1-CAPI-1.6.1" PROJ="Rel. 4.6.1, 21 August 2008" USE_STATS".
I installed PHP via the MAMP installs and I am using v5.2.13.

Thanks for any help here.
regina.leo (265) [Avatar] Offline
#2
Re: PHP not seeing PostGIS functions
No. I suspect the postgres account you are using in php doesn't have rights to the postgis functions. Use the grant wizard in php to give that account rights to teh functions.
regina.leo (265) [Avatar] Offline
#3
Re: PHP not seeing PostGIS functions
grant wizard in pgadmin I meant.
Steve_C (3) [Avatar] Offline
#4
Re: PHP not seeing PostGIS functions
Thanks so much for the quick response.

No change I'm afraid after applying all the grants.

I'm testing/debugging the php call to postgis with $res = pg_query('SELECT postgis_full_version()');

I get the following error message: Warning: pg_query() [function.pg-query]: Query failed: ERROR: function postgis_full_version() does not exist LINE 1: SELECT postgis_full_version() ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts. in /Applications/MAMP/htdocs/DevEnviron/main_4php_pg_demo.php on line 241

In pgAdmin3 I can see that the GRANT executes on postgis_full_version(), which is in the public schema of my database, are:
GRANT EXECUTE ON FUNCTION postgis_full_version() TO public;
GRANT EXECUTE ON FUNCTION postgis_full_version() TO postgres;
GRANT EXECUTE ON FUNCTION postgis_full_version() TO tpadm;

The owner is postgres.

I've tried logging on as postgres (as well as role tpadm who is a superuser), and am still getting the same error message.

Any further thoughts? Thanks
Steve_C (3) [Avatar] Offline
#5
Re: PHP not seeing PostGIS functions
Right, found my problem - user error of course! Your advice got me thinking along the right track.

The issue was that further back in my code I set the search path and I forgot to include public.

btw, great book - its helped me get started in the world of GIS. Its certainly complex when first approached but I can see its power!

and thanks once again for your quick response. Much appreciated!