Connect to exasol using php

osymo
Padawan

Hello everybody.

I'm a developper and my company is testing exasol. 

I have been asked to connect a PHP program to an exasol database which is not on the same host as the php program.

I have tried a lot syntaxe either using PHP PDO built in class or PHP odbc_connect() built-in function but nothing worked.

 

Do you guys have once conncted a php program to exasol ? How did you do that ?

 

Thanks for all in advance.

1 ACCEPTED SOLUTION

mwellbro
Xpert

Hi @osymo ,

welcome to the community !

accessing exasol from PHP ( not a web dev speaking here so caution advised 😉 ) seems more or less straight forward:

mwellbro_0-1628335158496.png

The "my_dsn" is an ODBC registration on my host, the exasol system is running on a VirtualBox ( so not strictly "not on the same host", but since the DSN on your PHP server would cover the connection string locality shouldn´t be an issue ).

Here´s the code in a more Copy&Paste-able format:

 

<?php

$connection = odbc_connect('my_dsn','sys','exasol');

$result = odbc_exec( $connection, "select param_value || ' accessed from PHP' from exa_metadata where param_name='databaseName'" );

while(odbc_fetch_row($result)){
       for($i=1;$i<=odbc_num_fields($result);$i++){
        echo "Result is ".odbc_result($result,$i);
    }
}
?>

 


What were your actual error messages ? I got stuck for a minute to config my XAMPP correctly ( i.e. add the necessary odbc extension ) but other than that it seemed pretty harmless.

 

Cheers,
Malte

View solution in original post

2 REPLIES 2

mwellbro
Xpert

Hi @osymo ,

welcome to the community !

accessing exasol from PHP ( not a web dev speaking here so caution advised 😉 ) seems more or less straight forward:

mwellbro_0-1628335158496.png

The "my_dsn" is an ODBC registration on my host, the exasol system is running on a VirtualBox ( so not strictly "not on the same host", but since the DSN on your PHP server would cover the connection string locality shouldn´t be an issue ).

Here´s the code in a more Copy&Paste-able format:

 

<?php

$connection = odbc_connect('my_dsn','sys','exasol');

$result = odbc_exec( $connection, "select param_value || ' accessed from PHP' from exa_metadata where param_name='databaseName'" );

while(odbc_fetch_row($result)){
       for($i=1;$i<=odbc_num_fields($result);$i++){
        echo "Result is ".odbc_result($result,$i);
    }
}
?>

 


What were your actual error messages ? I got stuck for a minute to config my XAMPP correctly ( i.e. add the necessary odbc extension ) but other than that it seemed pretty harmless.

 

Cheers,
Malte

View solution in original post

osymo
Padawan

Hello Malte.

Thanks a lot. For sure you saved me a lot of time 🙂

the part of your answer where you are saying  The "my_dsn" is an ODBC registration on my host 

made me think that I maybe had to register the dsn for exasol in the ODBC Data Source Administrator tool of windows (My operating system).

I did that with the help of this official tutorial https://docs.exasol.com/connect_exasol/drivers/odbc/odbc_windows.htm and every worked  😊

 

I'm even thinking of writing a Medium post explaining all the process, haha

Thank U again 🙂