Discussions
Categories
- 196.9K All Categories
- 2.2K Data
- 239 Big Data Appliance
- 1.9K Data Science
- 450.4K Databases
- 221.7K General Database Discussions
- 3.8K Java and JavaScript in the Database
- 31 Multilingual Engine
- 550 MySQL Community Space
- 478 NoSQL Database
- 7.9K Oracle Database Express Edition (XE)
- 3K ORDS, SODA & JSON in the Database
- 546 SQLcl
- 4K SQL Developer Data Modeler
- 187.1K SQL & PL/SQL
- 21.3K SQL Developer
- 295.9K Development
- 17 Developer Projects
- 138 Programming Languages
- 292.6K Development Tools
- 107 DevOps
- 3.1K QA/Testing
- 646K Java
- 28 Java Learning Subscription
- 37K Database Connectivity
- 155 Java Community Process
- 105 Java 25
- 22.1K Java APIs
- 138.1K Java Development Tools
- 165.3K Java EE (Java Enterprise Edition)
- 18 Java Essentials
- 160 Java 8 Questions
- 86K Java Programming
- 80 Java Puzzle Ball
- 65.1K New To Java
- 1.7K Training / Learning / Certification
- 13.8K Java HotSpot Virtual Machine
- 94.3K Java SE
- 13.8K Java Security
- 204 Java User Groups
- 24 JavaScript - Nashorn
- Programs
- 443 LiveLabs
- 38 Workshops
- 10.2K Software
- 6.7K Berkeley DB Family
- 3.5K JHeadstart
- 5.7K Other Languages
- 2.3K Chinese
- 171 Deutsche Oracle Community
- 1.1K Español
- 1.9K Japanese
- 232 Portuguese
oracle connection using php
target DB: 11.2.0.4.0 oracle 64 bit
Red Hat Enterprise Linux Server release 6.8 (Santiago) 64 bit
source server: red hat 7.8
[[email protected] lampp]# ./lampp version
Version: XAMPP for Linux 7.4.7-0
Hello Team,
I am getting error below when connecting using the form below:
<form name="form1" method="post" action="login.php">
<label> User Name
<input type="text" name="nis" id="nis">
</label>
<label> Password
<input type="password" name="password" id="password">
</label>
<label>
<input type="submit" name="submit" id="button" value="Login">
</label>
</form>
<?php
//create table users (userid varchar2(10), password varchar2(20), constraint pk_users primary key (userid));
//insert into users values('kharis', 'pass123');
$nis = isset($_POST['nis']) == true ? $_POST['nis'] : '';
$password= isset($_POST['password']) == true ? $_POST['password'] : '';
if(empty($nis) or empty($password)){
echo "UserID Password blank";}
else
{
$db = "(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = rhis-gaia-rpt01.mtg.local)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME =migr )
)
)" ;
$connect = oci_connect("migr");
$query = "SELECT * from users WHERE userid='".$nis."' and password='".$password."'";
$result = oci_parse($connect, $query);
oci_execute($result);
$tmpcount = oci_fetch($result);
if ($tmpcount==1) {
echo "Login Success";}
else
{
echo "Login Failed";
}
}
?>
Fatal error: Uncaught Error: Call to undefined function oci_connect() in /opt/lampp/htdocs/login.php:20 Stack trace: #0 {main} thrown in /opt/lampp/htdocs/login.php on line 20
Kindly help me.
Regards,
Joe
Answers
-
The common cause would be that environment variables like LD_LIBRARY_PATH (and maybe ORACLE_HOME if you have a DB installed on the same computer) are not propagated through the web server. How you need to set these varies with web servers & web server versions.
Maybe try adding the variables to /etc/apache2/envvars ? I found this on https://docs.joomla.org/Configuring_a_LAMPP_server_for_PHP_development/Linux_desktop
so it may not match what you have installed.
The next problem could be that you don't have OCI8 installed or enabled in php.ini : check this.
-
Kindly advise why OCI cannot be found in php info page after I added extension=oci8.so to /opt/lampp/etc/php.ini?
[[email protected] instantclient_11_2]# echo "instantclient,/opt/oracle/instantclient/instantclient_11_2" | pecl install oci8-2.0.12
WARNING: channel "pecl.php.net" has updated its protocols, use "pecl channel-update pecl.php.net" to update
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: 20100412
Zend Module Api No: 20100525
Zend Extension Api No: 220100525
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 /var/tmp/pear-build-oracle0WB3Z4/oci8-2.0.12
running: /var/tmp/oci8/configure --with-oci8=instantclient,/opt/oracle/instantclient/instantclient_11_2
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... /usr
checking for PHP includes... -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib
checking for PHP extension directory... /usr/lib64/php/modules
checking for PHP installed headers prefix... /usr/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.4.16, ok
checking OCI8 DTrace support... no
checking size of long int... 8
checking checking if we're on a 64-bit platform... yes
checking Oracle Instant Client directory... /opt/oracle/instantclient/instantclient_11_2
checking Oracle Instant Client SDK header directory... /opt/oracle/instantclient/instantclient_11_2/sdk/include
checking Oracle Instant Client library version compatibility... 11.1
checking how to print strings... printf
checking for a sed that does not truncate output... (cached) /usr/bin/sed
checking for fgrep... /usr/bin/grep -F
checking for ld used by cc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
checking the name lister (/usr/bin/nm -B) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 1966080
checking whether the shell understands some XSI constructs... yes
checking whether the shell understands "+="... yes
checking how to convert x86_64-unknown-linux-gnu file names to x86_64-unknown-linux-gnu format... func_convert_file_noop
checking how to convert x86_64-unknown-linux-gnu file names to toolchain format... func_convert_file_noop
checking for /usr/bin/ld option to reload object files... -r
checking for objdump... objdump
checking how to recognize dependent libraries... pass_all
checking for dlltool... no
checking how to associate runtime and link libraries... printf %s\n
checking for ar... ar
checking for archiver
checking for strip... strip
checking for ranlib... ranlib
checking for gawk... (cached) gawk
checking command to parse /usr/bin/nm -B output from cc object... ok
checking for sysroot... no
checking for mt... no
checking if : is a manifest tool... no
checking for dlfcn.h... yes
checking for objdir... .libs
checking if cc supports -fno-rtti -fno-exceptions... no
checking for cc option to produce PIC... -fPIC -DPIC
checking if cc PIC flag -fPIC -DPIC works... yes
checking if cc static flag -static works... no
checking if cc supports -c -o file.o... yes
checking if cc supports -c -o file.o... (cached) 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
configure: creating ./config.status
config.status: creating config.h
config.status: executing libtool commands
running: make
/bin/sh /var/tmp/pear-build-oracle0WB3Z4/oci8-2.0.12/libtool --mode=compile cc -I. -I/var/tmp/oci8 -DPHP_ATOM_INC -I/var/tmp/pear-build-oracle0WB3Z4/oci8-2.0.12/include -I/var/tmp/pear-build-oracle0WB3Z4/oci8-2.0.12/main -I/var/tmp/oci8 -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -I/opt/oracle/instantclient/instantclient_11_2/sdk/include -DHAVE_CONFIG_H -g -O2 -c /var/tmp/oci8/oci8.c -o oci8.lo
libtool: compile: cc -I. -I/var/tmp/oci8 -DPHP_ATOM_INC -I/var/tmp/pear-build-oracle0WB3Z4/oci8-2.0.12/include -I/var/tmp/pear-build-oracle0WB3Z4/oci8-2.0.12/main -I/var/tmp/oci8 -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -I/opt/oracle/instantclient/instantclient_11_2/sdk/include -DHAVE_CONFIG_H -g -O2 -c /var/tmp/oci8/oci8.c -fPIC -DPIC -o .libs/oci8.o
/bin/sh /var/tmp/pear-build-oracle0WB3Z4/oci8-2.0.12/libtool --mode=compile cc -I. -I/var/tmp/oci8 -DPHP_ATOM_INC -I/var/tmp/pear-build-oracle0WB3Z4/oci8-2.0.12/include -I/var/tmp/pear-build-oracle0WB3Z4/oci8-2.0.12/main -I/var/tmp/oci8 -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -I/opt/oracle/instantclient/instantclient_11_2/sdk/include -DHAVE_CONFIG_H -g -O2 -c /var/tmp/oci8/oci8_lob.c -o oci8_lob.lo
libtool: compile: cc -I. -I/var/tmp/oci8 -DPHP_ATOM_INC -I/var/tmp/pear-build-oracle0WB3Z4/oci8-2.0.12/include -I/var/tmp/pear-build-oracle0WB3Z4/oci8-2.0.12/main -I/var/tmp/oci8 -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -I/opt/oracle/instantclient/instantclient_11_2/sdk/include -DHAVE_CONFIG_H -g -O2 -c /var/tmp/oci8/oci8_lob.c -fPIC -DPIC -o .libs/oci8_lob.o
/bin/sh /var/tmp/pear-build-oracle0WB3Z4/oci8-2.0.12/libtool --mode=compile cc -I. -I/var/tmp/oci8 -DPHP_ATOM_INC -I/var/tmp/pear-build-oracle0WB3Z4/oci8-2.0.12/include -I/var/tmp/pear-build-oracle0WB3Z4/oci8-2.0.12/main -I/var/tmp/oci8 -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -I/opt/oracle/instantclient/instantclient_11_2/sdk/include -DHAVE_CONFIG_H -g -O2 -c /var/tmp/oci8/oci8_statement.c -o oci8_statement.lo
libtool: compile: cc -I. -I/var/tmp/oci8 -DPHP_ATOM_INC -I/var/tmp/pear-build-oracle0WB3Z4/oci8-2.0.12/include -I/var/tmp/pear-build-oracle0WB3Z4/oci8-2.0.12/main -I/var/tmp/oci8 -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -I/opt/oracle/instantclient/instantclient_11_2/sdk/include -DHAVE_CONFIG_H -g -O2 -c /var/tmp/oci8/oci8_statement.c -fPIC -DPIC -o .libs/oci8_statement.o
/bin/sh /var/tmp/pear-build-oracle0WB3Z4/oci8-2.0.12/libtool --mode=compile cc -I. -I/var/tmp/oci8 -DPHP_ATOM_INC -I/var/tmp/pear-build-oracle0WB3Z4/oci8-2.0.12/include -I/var/tmp/pear-build-oracle0WB3Z4/oci8-2.0.12/main -I/var/tmp/oci8 -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -I/opt/oracle/instantclient/instantclient_11_2/sdk/include -DHAVE_CONFIG_H -g -O2 -c /var/tmp/oci8/oci8_collection.c -o oci8_collection.lo
libtool: compile: cc -I. -I/var/tmp/oci8 -DPHP_ATOM_INC -I/var/tmp/pear-build-oracle0WB3Z4/oci8-2.0.12/include -I/var/tmp/pear-build-oracle0WB3Z4/oci8-2.0.12/main -I/var/tmp/oci8 -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -I/opt/oracle/instantclient/instantclient_11_2/sdk/include -DHAVE_CONFIG_H -g -O2 -c /var/tmp/oci8/oci8_collection.c -fPIC -DPIC -o .libs/oci8_collection.o
/bin/sh /var/tmp/pear-build-oracle0WB3Z4/oci8-2.0.12/libtool --mode=compile cc -I. -I/var/tmp/oci8 -DPHP_ATOM_INC -I/var/tmp/pear-build-oracle0WB3Z4/oci8-2.0.12/include -I/var/tmp/pear-build-oracle0WB3Z4/oci8-2.0.12/main -I/var/tmp/oci8 -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -I/opt/oracle/instantclient/instantclient_11_2/sdk/include -DHAVE_CONFIG_H -g -O2 -c /var/tmp/oci8/oci8_interface.c -o oci8_interface.lo
libtool: compile: cc -I. -I/var/tmp/oci8 -DPHP_ATOM_INC -I/var/tmp/pear-build-oracle0WB3Z4/oci8-2.0.12/include -I/var/tmp/pear-build-oracle0WB3Z4/oci8-2.0.12/main -I/var/tmp/oci8 -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -I/opt/oracle/instantclient/instantclient_11_2/sdk/include -DHAVE_CONFIG_H -g -O2 -c /var/tmp/oci8/oci8_interface.c -fPIC -DPIC -o .libs/oci8_interface.o
/bin/sh /var/tmp/pear-build-oracle0WB3Z4/oci8-2.0.12/libtool --mode=link cc -DPHP_ATOM_INC -I/var/tmp/pear-build-oracle0WB3Z4/oci8-2.0.12/include -I/var/tmp/pear-build-oracle0WB3Z4/oci8-2.0.12/main -I/var/tmp/oci8 -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -I/opt/oracle/instantclient/instantclient_11_2/sdk/include -DHAVE_CONFIG_H -g -O2 -o oci8.la -export-dynamic -avoid-version -prefer-pic -module -rpath /var/tmp/pear-build-oracle0WB3Z4/oci8-2.0.12/modules oci8.lo oci8_lob.lo oci8_statement.lo oci8_collection.lo oci8_interface.lo -Wl,-rpath,/opt/oracle/instantclient/instantclient_11_2 -L/opt/oracle/instantclient/instantclient_11_2 -lclntsh
libtool: link: cc -shared -fPIC -DPIC .libs/oci8.o .libs/oci8_lob.o .libs/oci8_statement.o .libs/oci8_collection.o .libs/oci8_interface.o -L/opt/oracle/instantclient/instantclient_11_2 -lclntsh -O2 -Wl,-rpath -Wl,/opt/oracle/instantclient/instantclient_11_2 -Wl,-soname -Wl,oci8.so -o .libs/oci8.so
libtool: link: ( cd ".libs" && rm -f "oci8.la" && ln -s "../oci8.la" "oci8.la" )
/bin/sh /var/tmp/pear-build-oracle0WB3Z4/oci8-2.0.12/libtool --mode=install cp ./oci8.la /var/tmp/pear-build-oracle0WB3Z4/oci8-2.0.12/modules
libtool: install: cp ./.libs/oci8.so /var/tmp/pear-build-oracle0WB3Z4/oci8-2.0.12/modules/oci8.so
libtool: install: cp ./.libs/oci8.lai /var/tmp/pear-build-oracle0WB3Z4/oci8-2.0.12/modules/oci8.la
libtool: finish: PATH="/usr/bin:/data/oracle/bin:/data/client32/instantclient_19_6:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/oracle/.local/bin:/home/oracle/bin:/sbin" ldconfig -n /var/tmp/pear-build-oracle0WB3Z4/oci8-2.0.12/modules
----------------------------------------------------------------------
Libraries have been installed in:
/var/tmp/pear-build-oracle0WB3Z4/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="/var/tmp/pear-build-oracle0WB3Z4/install-oci8-2.0.12" install
Installing shared extensions: /var/tmp/pear-build-oracle0WB3Z4/install-oci8-2.0.12/usr/lib64/php/modules/
running: find "/var/tmp/pear-build-oracle0WB3Z4/install-oci8-2.0.12" | xargs ls -dils
1167 0 drwxr-xr-x. 3 root root 17 Jul 22 14:26 /var/tmp/pear-build-oracle0WB3Z4/install-oci8-2.0.12
16800854 0 drwxr-xr-x. 3 root root 19 Jul 22 14:26 /var/tmp/pear-build-oracle0WB3Z4/install-oci8-2.0.12/usr
26883528 0 drwxr-xr-x. 3 root root 17 Jul 22 14:26 /var/tmp/pear-build-oracle0WB3Z4/install-oci8-2.0.12/usr/lib64
1168 0 drwxr-xr-x. 3 root root 21 Jul 22 14:26 /var/tmp/pear-build-oracle0WB3Z4/install-oci8-2.0.12/usr/lib64/php
8548671 0 drwxr-xr-x. 2 root root 21 Jul 22 14:26 /var/tmp/pear-build-oracle0WB3Z4/install-oci8-2.0.12/usr/lib64/php/modules
8555690 552 -rwxr-xr-x. 1 root root 561232 Jul 22 14:26 /var/tmp/pear-build-oracle0WB3Z4/install-oci8-2.0.12/usr/lib64/php/modules/oci8.so
Build process completed successfully
Installing '/usr/lib64/php/modules/oci8.so'
install ok: channel://pecl.php.net/oci8-2.0.12
configuration option "php_ini" is not set to php.ini location
You should add "extension=oci8.so" to php.ini
-
What i found weird is on the web page it is showing
But on server it shows
[[email protected] etc]# php -i
PHP Warning: Module 'oci8' already loaded in Unknown on line 0
phpinfo()
PHP Version => 5.4.16
-
You probably need to review the first suggestion I made about setting the library search path. If you have Instant Client (and no other Oracle software) installed on your computer, then you will find it easier to run ldconfig instead of setting LD_LIBRARY_PATH, see the Instant Client installation instructions.
And if you only have Instant Client, then try a recent version. Oracle 19c Instant Client will let you connect to Oracle Database version 11.2 or more recent.