Home » Php » linux – PHP odbc driver as shared extension

linux – PHP odbc driver as shared extension

Posted by: admin July 12, 2020 Leave a comment

Questions:

I am using php with version 5.6.31 in embedded project with yocto-linux as operating system. What I wants to do is have odbc driver as shared library instead of hard-link. Reason for this is I have 2 different use-cases with use PHP with one requiring custom-odbc-driver. Since I am building it for embedded domain due to space concern I doesn’t wants to add it statically in PHP binary. There is guide available to compile php extension as shared.

My questing is can we have odbc driver as shared library? guide mentioned that not all but few extension can be shared. I tried building PHP with config flag --with-custom-odbc=shared but it failed with fatal error:

odbc.h : No such file or directory .

--with-custom-odbc flag required path with odbc installation. If we can have odbc driver as shared library then which config flag should be used to describe it?

How to&Answers:

First install unixODBC-devel:

$ sudo yum install unixODBC unixODBC-devel

$ sudo repoquery --installed -l unixODBC-devel
/usr/include/autotest.h
/usr/include/odbcinst.h
/usr/include/odbcinstext.h
/usr/include/sql.h
/usr/include/sqlext.h
/usr/include/sqltypes.h
/usr/include/sqlucode.h
/usr/include/unixodbc_conf.h
/usr/include/unixodbc_conf_x86_64.h
/usr/include/uodbc_extras.h
/usr/include/uodbc_stats.h

$ odbcinst -j
unixODBC 2.3.1
DRIVERS............: /etc/odbcinst.ini
SYSTEM DATA SOURCES: /etc/odbc.ini
FILE DATA SOURCES..: /etc/ODBCDataSources
USER DATA SOURCES..: ~/.odbc.ini

$ odbcinst -q -d
[PostgreSQL]
[MySQL]

And then configure PHP with --with-unixODBC:

./configure --with-unixODBC=shared,/usr

When unixODBC is not available as package, it can also be built from source code:

$ wget http://www.unixodbc.org/unixODBC-2.3.7.tar.gz
$ tar -xvzf unixODBC-2.3.7.tar.gz
$ cd unixODBC-2.3.7
$ ./configure --help

$ ./configure
$ make
$ sudo make install

There’s even a Qt front-end for it: unixodbc-gui-qt.