PHP odbc driver as shared extension
Asked Answered
S

1

7

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?

Sola answered 14/12, 2018 at 6:26 Comment(1)
Well, there's this and this. Basically, you build with a link (which might be static or dynamic) to the ODBC driver manager (either iODBC or UnixODBC), which handles the dynamic loading of whatever ODBC drivers.Riding
A
4

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.

Alkalimeter answered 22/12, 2018 at 20:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.