Score:0

oracle db driver for php connection - ubuntu 20.04

bd flag

So I asked this question a few days ago but the topic was closed because I was running on ubuntu 16.04. Now I have updated to Ubuntu 20.04.3 LTS.

I have a php page on apache, and my oracble db connection:

$conn=odbc_connect("hostname","user","password");

gives me this error:

AH01071: Got error 'PHP message: PHP Warning: odbc_connect(): SQL error: [unixODBC][Driver Manager]Data source name not found, and no default driver specified, SQL state IM002 in SQLConnect

I understand I need to install a driver to make it work, but I am not sure which one?
Being a oracle database on a different location, it is mandatory to have java (jdk) installed on my machine?

in flag
Was [the link I posted](https://askubuntu.com/questions/1358771/oracle-db-driver-for-php-connection-ubuntu-16-php7-4#comment2327376_1358771) insufficient?
Score:0
cn flag

Your programming language is obviously PHP, so it has nothing to do with Java, JDK, JDBC or whatsoever.

I am going to summarize two sources, because IMHO they are good enough so that it is not necessary to replicate everything here.

For PHP, the easiest way to go is to use Oracle Instant Client and PHP Database Object (PDO).

Summary from the Ubuntu Wiki:

Install the following packages, which are available als RPM packages on Oracle's website:

oracle-instantclient-basiclite
oracle-instantclient-devel
oracle-instantclient-sqlplus

Next, install PHP OCI8: See here, beginning from step 7. To summarize: The core command to be issued is to install it via PHP PECL:

pecl install oci8   # PHP 8
pecl install oci8-2.2.0    # PHP 7.x

Last but not least, make sure that the php.ini (depending on if you are using PHP-CLI or PHP-FPM it may be /etc/php/VERSION/php-cli or /etc/php/VERSION/php-fpm, where VERSION may be something like 7.4 or 8.0) loads the OCI driver:

extension=oci8
extension=pdo_oci

That should be everything. If there are any other troubles, please refer to the Ubuntu Wiki I linked above. For me, these steps were enough.

$dbconn = new PDO('oci:dbname=MY_CONNENCTION', 'username', 'pa55w0rd');

MY_CONNECTION can be either the name as provided in the file tnsnames.org, or the entire long connection string which is provided on the right hand side of the equals (=) sign in the file tnsnames.ora, usually beginning with (DESCRIPTION= or (DESCRIPTION_LIST=.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.