I want to create a table from a shapefile in PostgreSQL. To do that, I can run this command in cmd:
shp2pgsql -s 4326 -W LATIN1 E:\Any\THA_adm public.test123 | psql -h localhost -d DATA -U postgres -w 123;
This works, but I want to run it from PHP. How can I do that, I tried PHP functions:
- shell_exec()
- exec()
- system()
but did not work. Is there any other way to create a table from shape in PHP or run this command?
Best Answer
I experienced exactly the same problem (command works in cmd but nothing when called via PHP). What helped me a lot was to retrieve the error message (by adding: 2>&1'& $output). MY command looked something like:
It returned "'psql' is not recognized as an internal or external command,operable program or batch file." My fix was to define the full path of the psql executable in the command like this: