Reputation: 3952
How can I connect PHP to an H2 database, so far I tried starting the embedded server with a
$ java -cp h2-1.3.172.jar org.h2.tools.Server
Web Console server running at http://127.0.1.1:8082 (others can connect)
TCP server running at tcp://127.0.1.1:9092 (only local connections)
PG server running at pg://127.0.1.1:5435 (only local connections)
installing the pg-sql module under ubuntu
sudo apt-get install php5-pgsql
then in my php I have the following
$conn = pg_connect("host=127.0.1.1 port=5435 dbname=/home/frank/testdb user=sa password=");
Also tried different ports: 5435, 9092, different host: localhost, 127.0.0.1 but nothing, the returned connection is null or the script hangs.
Any suggestion?
Upvotes: 2
Views: 7383
Reputation: 273
I had it working last year while executing the PHP code in a Java servlet. My experiment is available at https://github.com/webdevelopersdiary/jamp . It's backed by Quercus, and redirects PHP database connection attempts to H2 (at least it does for MySQL, haven't tested for PSQL, but it may do the same in that case). Also note that H2's "compatibility mode" is very rudimentary, it still breaks on pretty standard PSQL stuff that you feed it.
Upvotes: 1
Reputation: 453
pg_connect is used to connect to PostrgeSQL database server, not for H2DB. Those are completely different products and are not compatibile
To connect to H2 you can use php-java bridge and some custom java class to expose required functionalities to php client
Upvotes: 1