Extensions
Sommaire
Présentation
Cette page a pour objet de présenter certaines extensions de PHP.
OCI8
Présentation
Cette extension apportent des fonctions qui permettent d'accéder aux bases de données Oracle 19c, 18c, 12c, 11g, 10g, 9i et 8i. Elles supportent les commandes SQL et PL/SQL. Les fonctions de base incluent le contrôle de transaction, la liaison de variables PHP avec des conteneurs Oracle, le support des types de grands objets (LOB) et des collections. Les fonctions d'extensibilité de Oracle, telles que de Database Resident Connection Pooling (DRCP) et le cache de résultats sont aussi supportés.
Plus d'informations sur https://www.php.net/manual/fr/book.oci8.php.
Prérequis
La présence des librairies de l'Instant Client d'Oracle est obligatoire pour l'installation de l'extension oci8.
Installation
Par le gestionnaire de paquets
Valable uniquement si PHP a été installé par le gestionnaire de paquet également.
Lancer la commande :
yum install php-oci8
Cela aura pour effet d'installer oci8 en tant que module partagé. Pour l'activer, modifier le fichier php.ini
et ajouter/modifier la ligne suivante :
extension=oci8.so
Lors de la compilation de PHP
Lors de la configuration de la compilation de PHP, ajouter la ligne suivante :
... --with-oci8=instantclient,/usr/lib/oracle/10.2.0.4/client64/lib \ ...
Remplacer /usr/lib/oracle/10.2.0.4/client64/lib
par le chemin correspondant à la version d'Instant Client d'installée.
Avec PECL
Indiquer à PECL la localisation du fichier php.ini
:
pear config-set php_ini /local/php/php-5.6.40/php.ini
Mettre à jour la base PECL :
pecl channel-update pecl.php.net
Voici le détail du package oci8 : https://pecl.php.net/package/oci8.
Grâce à ces informations, il faut choisir la version du package PECL oci8 correspondant à la version de PHP.
Par exemple, pour PHP 5.6.40, il faut lancer la commande suivante :
pecl install oci8-2.0.12
Alors que pour la version 7.4.7, il faudra simplement lancer la commande :
pecl install oci8
Exemple de retour :
[root@vmwcentos7 ~]# /local/php/php-5.6.40/bin/pecl install oci8-2.0.12 downloading oci8-2.0.12.tgz ... Starting to download oci8-2.0.12.tgz (191,954 bytes) .........................................done: 191,954 bytes 11 source files, building running: phpize Configuring for: PHP Api Version: 20131106 Zend Module Api No: 20131226 Zend Extension Api No: 220131226 Please provide the path to the ORACLE_HOME directory. Use 'instantclient,/path/to/instant/client/lib' if you're compiling with Oracle Instant Client [autodetect] : building in /tmp/pear/temp/pear-build-rootnlbXUf/oci8-2.0.12 running: /tmp/pear/temp/oci8/configure --with-php-config=/local/php/php-5.6.40/bin/php-config --with-oci8 checking for grep that handles long lines and -e... /usr/bin/grep checking for egrep... /usr/bin/grep -E checking for a sed that does not truncate output... /usr/bin/sed checking for cc... cc checking whether the C compiler works... yes checking for C compiler default output file name... a.out checking for suffix of executables... checking whether we are cross compiling... no checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether cc accepts -g... yes checking for cc option to accept ISO C89... none needed checking how to run the C preprocessor... cc -E checking for icc... no checking for suncc... no checking whether cc understands -c and -o together... yes checking for system library directory... lib checking if compiler supports -R... no checking if compiler supports -Wl,-rpath,... yes checking build system type... x86_64-unknown-linux-gnu checking host system type... x86_64-unknown-linux-gnu checking target system type... x86_64-unknown-linux-gnu checking for PHP prefix... /local/php/php-5.6.40 checking for PHP includes... -I/local/php/php-5.6.40/include/php -I/local/php/php-5.6.40/include/php/main -I/local/php/php-5.6.40/include/php/TSRM -I/local/php/php-5.6.40/include/php/Zend -I/local/php/php-5.6.40/include/php/ext -I/local/php/php-5.6.40/include/php/ext/date/lib checking for PHP extension directory... /local/php/php-5.6.40/lib/php/extensions/no-debug-non-zts-20131226 checking for PHP installed headers prefix... /local/php/php-5.6.40/include/php checking if debug is enabled... no checking if zts is enabled... no checking for re2c... no configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers. checking for gawk... gawk checking for Oracle Database OCI8 support... yes, shared checking PHP version... 5.6.40, ok checking OCI8 DTrace support... no checking size of long int... 8 checking checking if we're on a 64-bit platform... yes configure: WARNING: OCI8 extension: ORACLE_HOME is not set, looking for default Oracle Instant Client instead checking Oracle Instant Client directory... /usr/lib/oracle/19.6/client64/lib checking Oracle Instant Client SDK header directory... /usr/include/oracle/19.6/client64 checking Oracle Instant Client library version compatibility... 19.1 checking for ld used by cc... /usr/bin/ld checking if the linker (/usr/bin/ld) is GNU ld... yes checking for /usr/bin/ld option to reload object files... -r checking for BSD-compatible nm... /usr/bin/nm -B checking whether ln -s works... yes checking how to recognize dependent libraries... pass_all checking dlfcn.h usability... yes checking dlfcn.h presence... yes checking for dlfcn.h... yes checking the maximum length of command line arguments... 1572864 checking command to parse /usr/bin/nm -B output from cc object... ok checking for objdir... .libs checking for ar... ar checking for ranlib... ranlib checking for strip... strip checking if cc supports -fno-rtti -fno-exceptions... no checking for cc option to produce PIC... -fPIC checking if cc PIC flag -fPIC works... yes checking if cc static flag -static works... no checking if cc supports -c -o file.o... yes checking whether the cc linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes checking whether -lc should be explicitly linked in... no checking dynamic linker characteristics... GNU/Linux ld.so checking how to hardcode library paths into programs... immediate checking whether stripping libraries is possible... yes checking if libtool supports shared libraries... yes checking whether to build shared libraries... yes checking whether to build static libraries... no creating libtool appending configuration tag "CXX" to libtool configure: creating ./config.status config.status: creating config.h running: make /bin/sh /tmp/pear/temp/pear-build-rootnlbXUf/oci8-2.0.12/libtool --mode=compile cc -I. -I/tmp/pear/temp/oci8 -DPHP_ATOM_INC -I/tmp/pear/temp/pear-build-rootnlbXUf/oci8-2.0.12/include -I/tmp/pear/temp/pear-build-rootnlbXUf/oci8-2.0.12/main -I/tmp/pear/temp/oci8 -I/local/php/php-5.6.40/include/php -I/local/php/php-5.6.40/include/php/main -I/local/php/php-5.6.40/include/php/TSRM -I/local/php/php-5.6.40/include/php/Zend -I/local/php/php-5.6.40/include/php/ext -I/local/php/php-5.6.40/include/php/ext/date/lib -I/usr/include/oracle/19.6/client64 -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/temp/oci8/oci8.c -o oci8.lo mkdir .libs cc -I. -I/tmp/pear/temp/oci8 -DPHP_ATOM_INC -I/tmp/pear/temp/pear-build-rootnlbXUf/oci8-2.0.12/include -I/tmp/pear/temp/pear-build-rootnlbXUf/oci8-2.0.12/main -I/tmp/pear/temp/oci8 -I/local/php/php-5.6.40/include/php -I/local/php/php-5.6.40/include/php/main -I/local/php/php-5.6.40/include/php/TSRM -I/local/php/php-5.6.40/include/php/Zend -I/local/php/php-5.6.40/include/php/ext -I/local/php/php-5.6.40/include/php/ext/date/lib -I/usr/include/oracle/19.6/client64 -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/temp/oci8/oci8.c -fPIC -DPIC -o .libs/oci8.o /bin/sh /tmp/pear/temp/pear-build-rootnlbXUf/oci8-2.0.12/libtool --mode=compile cc -I. -I/tmp/pear/temp/oci8 -DPHP_ATOM_INC -I/tmp/pear/temp/pear-build-rootnlbXUf/oci8-2.0.12/include -I/tmp/pear/temp/pear-build-rootnlbXUf/oci8-2.0.12/main -I/tmp/pear/temp/oci8 -I/local/php/php-5.6.40/include/php -I/local/php/php-5.6.40/include/php/main -I/local/php/php-5.6.40/include/php/TSRM -I/local/php/php-5.6.40/include/php/Zend -I/local/php/php-5.6.40/include/php/ext -I/local/php/php-5.6.40/include/php/ext/date/lib -I/usr/include/oracle/19.6/client64 -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/temp/oci8/oci8_lob.c -o oci8_lob.lo cc -I. -I/tmp/pear/temp/oci8 -DPHP_ATOM_INC -I/tmp/pear/temp/pear-build-rootnlbXUf/oci8-2.0.12/include -I/tmp/pear/temp/pear-build-rootnlbXUf/oci8-2.0.12/main -I/tmp/pear/temp/oci8 -I/local/php/php-5.6.40/include/php -I/local/php/php-5.6.40/include/php/main -I/local/php/php-5.6.40/include/php/TSRM -I/local/php/php-5.6.40/include/php/Zend -I/local/php/php-5.6.40/include/php/ext -I/local/php/php-5.6.40/include/php/ext/date/lib -I/usr/include/oracle/19.6/client64 -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/temp/oci8/oci8_lob.c -fPIC -DPIC -o .libs/oci8_lob.o /bin/sh /tmp/pear/temp/pear-build-rootnlbXUf/oci8-2.0.12/libtool --mode=compile cc -I. -I/tmp/pear/temp/oci8 -DPHP_ATOM_INC -I/tmp/pear/temp/pear-build-rootnlbXUf/oci8-2.0.12/include -I/tmp/pear/temp/pear-build-rootnlbXUf/oci8-2.0.12/main -I/tmp/pear/temp/oci8 -I/local/php/php-5.6.40/include/php -I/local/php/php-5.6.40/include/php/main -I/local/php/php-5.6.40/include/php/TSRM -I/local/php/php-5.6.40/include/php/Zend -I/local/php/php-5.6.40/include/php/ext -I/local/php/php-5.6.40/include/php/ext/date/lib -I/usr/include/oracle/19.6/client64 -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/temp/oci8/oci8_statement.c -o oci8_statement.lo cc -I. -I/tmp/pear/temp/oci8 -DPHP_ATOM_INC -I/tmp/pear/temp/pear-build-rootnlbXUf/oci8-2.0.12/include -I/tmp/pear/temp/pear-build-rootnlbXUf/oci8-2.0.12/main -I/tmp/pear/temp/oci8 -I/local/php/php-5.6.40/include/php -I/local/php/php-5.6.40/include/php/main -I/local/php/php-5.6.40/include/php/TSRM -I/local/php/php-5.6.40/include/php/Zend -I/local/php/php-5.6.40/include/php/ext -I/local/php/php-5.6.40/include/php/ext/date/lib -I/usr/include/oracle/19.6/client64 -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/temp/oci8/oci8_statement.c -fPIC -DPIC -o .libs/oci8_statement.o /bin/sh /tmp/pear/temp/pear-build-rootnlbXUf/oci8-2.0.12/libtool --mode=compile cc -I. -I/tmp/pear/temp/oci8 -DPHP_ATOM_INC -I/tmp/pear/temp/pear-build-rootnlbXUf/oci8-2.0.12/include -I/tmp/pear/temp/pear-build-rootnlbXUf/oci8-2.0.12/main -I/tmp/pear/temp/oci8 -I/local/php/php-5.6.40/include/php -I/local/php/php-5.6.40/include/php/main -I/local/php/php-5.6.40/include/php/TSRM -I/local/php/php-5.6.40/include/php/Zend -I/local/php/php-5.6.40/include/php/ext -I/local/php/php-5.6.40/include/php/ext/date/lib -I/usr/include/oracle/19.6/client64 -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/temp/oci8/oci8_collection.c -o oci8_collection.lo cc -I. -I/tmp/pear/temp/oci8 -DPHP_ATOM_INC -I/tmp/pear/temp/pear-build-rootnlbXUf/oci8-2.0.12/include -I/tmp/pear/temp/pear-build-rootnlbXUf/oci8-2.0.12/main -I/tmp/pear/temp/oci8 -I/local/php/php-5.6.40/include/php -I/local/php/php-5.6.40/include/php/main -I/local/php/php-5.6.40/include/php/TSRM -I/local/php/php-5.6.40/include/php/Zend -I/local/php/php-5.6.40/include/php/ext -I/local/php/php-5.6.40/include/php/ext/date/lib -I/usr/include/oracle/19.6/client64 -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/temp/oci8/oci8_collection.c -fPIC -DPIC -o .libs/oci8_collection.o /bin/sh /tmp/pear/temp/pear-build-rootnlbXUf/oci8-2.0.12/libtool --mode=compile cc -I. -I/tmp/pear/temp/oci8 -DPHP_ATOM_INC -I/tmp/pear/temp/pear-build-rootnlbXUf/oci8-2.0.12/include -I/tmp/pear/temp/pear-build-rootnlbXUf/oci8-2.0.12/main -I/tmp/pear/temp/oci8 -I/local/php/php-5.6.40/include/php -I/local/php/php-5.6.40/include/php/main -I/local/php/php-5.6.40/include/php/TSRM -I/local/php/php-5.6.40/include/php/Zend -I/local/php/php-5.6.40/include/php/ext -I/local/php/php-5.6.40/include/php/ext/date/lib -I/usr/include/oracle/19.6/client64 -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/temp/oci8/oci8_interface.c -o oci8_interface.lo cc -I. -I/tmp/pear/temp/oci8 -DPHP_ATOM_INC -I/tmp/pear/temp/pear-build-rootnlbXUf/oci8-2.0.12/include -I/tmp/pear/temp/pear-build-rootnlbXUf/oci8-2.0.12/main -I/tmp/pear/temp/oci8 -I/local/php/php-5.6.40/include/php -I/local/php/php-5.6.40/include/php/main -I/local/php/php-5.6.40/include/php/TSRM -I/local/php/php-5.6.40/include/php/Zend -I/local/php/php-5.6.40/include/php/ext -I/local/php/php-5.6.40/include/php/ext/date/lib -I/usr/include/oracle/19.6/client64 -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/temp/oci8/oci8_interface.c -fPIC -DPIC -o .libs/oci8_interface.o /bin/sh /tmp/pear/temp/pear-build-rootnlbXUf/oci8-2.0.12/libtool --mode=link cc -DPHP_ATOM_INC -I/tmp/pear/temp/pear-build-rootnlbXUf/oci8-2.0.12/include -I/tmp/pear/temp/pear-build-rootnlbXUf/oci8-2.0.12/main -I/tmp/pear/temp/oci8 -I/local/php/php-5.6.40/include/php -I/local/php/php-5.6.40/include/php/main -I/local/php/php-5.6.40/include/php/TSRM -I/local/php/php-5.6.40/include/php/Zend -I/local/php/php-5.6.40/include/php/ext -I/local/php/php-5.6.40/include/php/ext/date/lib -I/usr/include/oracle/19.6/client64 -DHAVE_CONFIG_H -g -O2 -o oci8.la -export-dynamic -avoid-version -prefer-pic -module -rpath /tmp/pear/temp/pear-build-rootnlbXUf/oci8-2.0.12/modules oci8.lo oci8_lob.lo oci8_statement.lo oci8_collection.lo oci8_interface.lo -Wl,-rpath,/usr/lib/oracle/19.6/client64/lib -L/usr/lib/oracle/19.6/client64/lib -lclntsh cc -shared .libs/oci8.o .libs/oci8_lob.o .libs/oci8_statement.o .libs/oci8_collection.o .libs/oci8_interface.o -L/usr/lib/oracle/19.6/client64/lib -lclntsh -Wl,-rpath -Wl,/usr/lib/oracle/19.6/client64/lib -Wl,-soname -Wl,oci8.so -o .libs/oci8.so creating oci8.la (cd .libs && rm -f oci8.la && ln -s ../oci8.la oci8.la) /bin/sh /tmp/pear/temp/pear-build-rootnlbXUf/oci8-2.0.12/libtool --mode=install cp ./oci8.la /tmp/pear/temp/pear-build-rootnlbXUf/oci8-2.0.12/modules cp ./.libs/oci8.so /tmp/pear/temp/pear-build-rootnlbXUf/oci8-2.0.12/modules/oci8.so cp ./.libs/oci8.lai /tmp/pear/temp/pear-build-rootnlbXUf/oci8-2.0.12/modules/oci8.la PATH="$PATH:/sbin" ldconfig -n /tmp/pear/temp/pear-build-rootnlbXUf/oci8-2.0.12/modules
Libraries have been installed in: /tmp/pear/temp/pear-build-rootnlbXUf/oci8-2.0.12/modules If you ever happen to want to link against installed libraries in a given directory, LIBDIR, you must either use libtool, and specify the full pathname of the library, or use the `-LLIBDIR' flag during linking and do at least one of the following: - add LIBDIR to the `LD_LIBRARY_PATH' environment variable during execution - add LIBDIR to the `LD_RUN_PATH' environment variable during linking - use the `-Wl,--rpath -Wl,LIBDIR' linker flag - have your system administrator add LIBDIR to `/etc/ld.so.conf' See any operating system documentation about shared libraries for more information, such as the ld(1) and ld.so(8) manual pages.
Build complete. Don't forget to run 'make test'. running: make INSTALL_ROOT="/tmp/pear/temp/pear-build-rootnlbXUf/install-oci8-2.0.12" install Installing shared extensions: /tmp/pear/temp/pear-build-rootnlbXUf/install-oci8-2.0.12/local/php/php-5.6.40/lib/php/extensions/no-debug-non-zts-20131226/ running: find "/tmp/pear/temp/pear-build-rootnlbXUf/install-oci8-2.0.12"
SQL Server
Pour pouvoir communiquer avec les serveurs SQL Server de Microsoft depuis un serveur Linux avec PHP, il est nécessaire d'installer les pilotes ODBC pour SQL Server.
Pour ce faire, installer le dépôt Microsoft pour la version de Linux nécessaire :
curl https://packages.microsoft.com/config/rhel/7/prod.repo > /etc/yum.repos.d/mssql-release.repo
Ensuite, installer la version désirée du pilote ODBC MicroSoft : ACCEPT_EULA=Y yum install msodbcsql17
Une fois le pilote installé, il faut ensuite installer l'extension nécessaire dans PHP.
PHP 7
Pour pouvoir communiquer avec les serveurs SQL Server de Microsoft avec PHP 7, il faut installer l'extension sqlsrv
ou son homologue en PDO pdo_sqlsrv
.
Pour ce faire, il est possible de l'installer via le gestionnaire de paquets (moyennant l'ajout du dépôt correspondant), ou de recompiler intégralement PHP, ou de compiler uniquement l'extension grâce à PECL.
Pour une installation au travers de PECL, lancer les commandes suivantes :
pecl channel-update pecl.php.net pecl install pdo_sqlsrv
PHP 5
Pour pouvoir communiquer avec les serveurs SQL Server de Microsoft avec PHP 5, plusieurs solutions sont possibles.
Les différentes solutions sont résumées sur un article sur le blog de Rémi : https://blog.remirepo.net/post/2016/09/20/Microsoft-SQL-Server-depuis-PHP
Avec PDO
Pour pouvoir faire du PDO sur des serveurs SQL Server depuis un serveur Linux avec PHP 5, il faut, au choix :
- Installer le paquet
mssqlodbc
depuis le repository de Rémi (voir lien ci-dessus) - Recompiler PHP
Dans les deux cas, le paquet unixODBC
est nécessaire.
Pour installer les prérequis nécessaire à la recompilation de PHP, lancer la commande suivante :
yum install unixODBC-devel msodbcsql17
Lancer ensuite la recompilation de PHP en y ajoutant l'option suivante :
... --with-pdo-odbc=unixODBC,/usr \ ...
Voici un exemple de code PHP fonctionnel pour se connecter à un SQL Server 2014 :
<?php
try {
$dbh = new PDO('odbc:DRIVER={ODBC Driver 17 for SQL Server};Server=MyServer\MyInstance,MyPort;UID=MyUserName;PWD=MyPassword;');
} catch (PDOException $exception) {
echo $exception->getMessage();
exit;
}
var_dump($dbh);
unset($dbh);
echo "Connexion OK !";
?>