How to connect JDBC (H2 Database) in PHP?

4

How to connect a JDBC database (specifically H2 Database) in PHP? The database is in a single file with extension .db

    
asked by anonymous 17.10.2015 / 17:27

1 answer

4

According to the link link:

  

PHP support: H2 should support PDO, or test with PostgreSQL PDO.

     

PHP support: H2 must support PDO or test with PostgreSQL PDO

I can not test H2 here, but if the link is correct then you can use the PDO for PostgreSQL. At the moment the databases supported by the PDO are:

  • CUBRID
  • MS SQL Server
  • Firebird
  • IBM
  • Informix
  • MySQL
  • MS SQL Server
  • Oracle
  • ODBC and DB2
  • PostgreSQL
  • SQLite
  • 4D

And there is no specific driver for H2 Database , but as stated earlier you can try the PostgreSQL / em>.

Something like:

$db = new PDO('pgsql:dbname=mydb;host=localhost;user=usuario;password=senha');

If this is possible, it is likely that there is no full compatibility and from what I have researched, it seems to be a very difficult job and hardly anyone could do this.

Another detail, I'm not sure, but I believe that h2 database is supported by ODBC and maybe you can use it with PDO like this.

Other than this you can try using link which is an independent PHP platform with support for banks in java ( in java? )

To configure jdbc with h2 database go to src/main/webapp/WEB-INF/jetty-env.xml and change the line:

<Set name="url">jdbc:h2:mem:database;IGNORECASE=TRUE;MODE=MYSQL</Set>

for

<Set name="url">jdbc:h2:file:filename;IGNORECASE=TRUE;MODE=MYSQL</Set>

Where you replaced with filename should be the relative path to a file (relative to pom.xml ) or an absolute path to a file (in case of something like jdbc:h2:file:c:\users\usuario\desktop\banco;IGNORECASE=TRUE;MODE=MYSQL ). For more information about H2 JDBC see the list of H2 Database resources a>.

Even though you can connect, I still believe this is not a good idea for the production environment because of probable instabilities for lack of compatibility, so I recommend converting your database to mysql or another bank supported by default by PDO.

    
18.10.2015 / 18:07