I am trying to make a connection from PHP Version 5.5.27 to Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64 bit Production
Downloaded instant client version 11.2.0.3.0 and linked it in system's PATH variable
Also I have enabled extension=php_oci8.dll in my php.ini
but still not working, I get this error:
Warning: oci_connect(): OCIEnvNlsCreate() failed. There is something wrong with your system - please check that PATH includes the directory with Oracle Instant Client libraries in C:\xampp\htdocs\test.php on line 3
Here is the step-by-step procedure that helped me connecting Oracle with PHP:
First install Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64 bit Production. Make sure its working.
Download msvcp110.dll and msvcr110.dll (download dll's only. Don't download them from microsoft.com. Download them from some other source instead).
Copy both files directly into Windows/System32 folder.
Restart Computer.
Install WAMP server.
Make sure both Oracle and WAMP Server are installed in same drives. I have them in C:
Check if WAMP is working. (the W logo turns green).
Once its Green, click on it, go on PHP, then to PHP Extensions.
Now check php_oci8.
WAMP will restart its services.
Now from same menu, check php_oci8_11g
WAMP will restart again now.
Restart your computer.
Download 'instantclient-basic-win-x86-64-11.2.0.1.0'
Extract it in C:.
Go to Control Panel > Environment Variable (Search for Environment Variables in control panel)
Under 'Advanced' tab, click Environment Variables.
In System Variables (section below), Click 'New...'
Fill the form; Variable Name: PATH, Variable Value: C:\instantclient_11_2.
Apply Changes.
Restart Computer.
Oracle and PHP are connected.
Make new database in oracle. Notedown the username, password and service name while creating database.
write your SQL script.
Make php file in wamp/www folder
write php script to fetch data from same database you created in oracle.
in php script, write oci_connect('username', 'password', 'localhost/service name').
save php file and run in in browser you specifed while installing WAMP.
Related
I am getting error when I trying from browser.
Warning: oci_connect(): ORA-28759: failure to open file in
/var/www/myapp/abc.php on line 16
Fatal error: ORA-28759: failure to open file in /var/www/myapp/abc.php on
line 19
But when running same file from Server terminal as a root user > PHP abc.php that time oracle database output is coming.
I didn't understand why is running from terminal but not on browser.
I am using PHP7, Apache and Installed Oracle 19c home db.
I am using oci_connect to communication with oracle database from PHP code.
I think there is some permission issue to my httpd (apahce).
Please give suggestion.
Check that the web server process has access to all the Oracle client libraries and data files. Since you are using an Oracle home, make sure all the directories have 'other' access permissions set. Typically user home directories don't have this by default.
Since the app is running, some libraries are being loaded so maybe permissions are OK? Make sure you have the web server process environment variables the same as those used by your command shell to make sure the same set of Oracle client libraries are being used. (Do you also have Instant Client installed somewhere, or another Oracle home??).
The recent common causes of 'ORA-28759: failure to open file' are when Oracle cloud wallets are being used and the sqlnet.ora path to the wallet (the DIRECTORY=... bit) is not valid. ​Check the path is OK, or the Oracle Net configuration files are in the default location (and are readable). Note that with Instant Client 19.14 you can use 1-way TLS so wallets are not always needed, depending on your net configuration.
I doubt there is a problem with php.ini, since you are obviously able to call OCI8 functions. The php.ini file doesn't control behaviors of the Oracle Client libraries that are throwing the error.
Update your question with more details about how you are setting the environment and what Oracle configuration files are being used for connecting
I am just trying to set up a Oracle instant client 19 database connection using PHP and XAMPP.
I have followed several Youtube videos, other stack posts and it still does not show the oci8 module on phpinfo.php. I also recieve the error Call to undefined function oci_connect()
What I have done:
Installed XAMPP with PHP enabled.
Downloaded Version 19.9.0.0.0 Basic x64 from - https://www.oracle.com/uk/database/technologies/instant-client/winx64-64-downloads.html and extracted to C:\ named instantclient_19_9
Set up my environment path = C:\instantclient_19_9
Restarted PC
Downloaded oci.dll from - http://pecl.php.net/package/oci8/2.0.8/windows
Selected 5.5 Safe thread x64
Extracted into C:/xampp/php/ext
Went into php.ini and removed semi-colon from extension=oci8_19
Restarted Apache
Looking in XAMPP/php/ext, there is php_oci8.dll and php_oci8_19.dll extensions there.
Went onto phpinfo.php and nothing is displaying for oci8
Not sure what else I need to do, at this point, all walkthroughs show their phpinfo pages and they all show the oci extension. I tried uninstalling XAMPP and removing all files then trying again but each time it doesn't work so I must be missing something. I have done this for SQLITE and MYSQL and they worked just fine, just oracle.
For extra measures, I have also tried an answer someone suggested in a post and it also hasn't worked:
Add oci.dll, oraociei19.dll, and oraons.dll from C:\instantclient_19_9 to xampp/apache/bin folder. Replace the existing ones.
Restart the Apache
In order to access an remote Oracle database from php, I had to activate the extension php_oci8_12c. But when I do, it does not appear in the phpinfo().
On the other hand, I get in the php logs the error message:
[13-Jan-2017 08:39:48 UTC] PHP Warning: PHP Startup: Unable to load dynamic library 'c:/wamp64/bin/php/php7.0.10/ext/php_oci8_12c.dll' - %1 is not a Valid win32 application
I use php 5.6.25 and wampserver 3.0.6 (64 bit). How can I resolve this?
Well, I faced this error too and managed to fix it.
Before downloading every kind Oracle Client Version just take a look at your http://localhost/?phpinfo settings at Configure Command section.
This will tell, which version of Oracle was used to build your WAMP server.
The image above show this two lines:
"--with-pdo-oci=c:\php-sdk\oracle\x64\instantclient_12_1\sdk,shared"
"--with-oci8-12c=c:\php-sdk\oracle\x64\instantclient_12_1\sdk,shared"
Obviously tell us that InstantClient used is 64 bits.
There are two versions of InstantClient 12.1 x64: 12.1.0.2.0 and 12.1.0.1.0
I tested with 12.1.0.2.0 version and failed.
After that, I tested with old one, 12.1.0.1.0 version and worked.
Download from Instant Client for Microsoft Windows (x64) and extract the files below to "c:\oracle":
instantclient-basic-windows.x64-12.1.0.2.0.zip
instantclient-sqlplus-windows.x64-12.1.0.2.0.zip
instantclient-sdk-windows.x64-12.1.0.2.0.zip
This will create the following folder "C:\Oracle\instantclient_12_1".
Using "Windows Command Prompt" (WIN+R CMD) go to folder above and execute SQLPLUS:
sqlplus [user]/[pass]#[host]:[port]/[service]
You must be able to connect.
Finally, add the "C:\Oracle\instantclient_12_1" folder to the PATH enviroment variable, placing it on the leftmost place.
Close your WAMP server.
Yes close it, because the Enviroment Variable is only read at launch time.
So restarting the services may fail, leading you to a wrong result.
After restart, your PHPINFO would show the OCI8 and PDO_OCI loaded.
I hope it helps!
I'm trying to move over to PHP7 and use the latest EasyPHP but I can't for the life of me figure out how to connect to MySQL using the PDO
I've set up a working directory:
C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\TechMexv3 with cURL
I've installed all my database tables in phpMyAdmin which has worked fine
I'm now trying to connect with the following:
$DBH = new PDOEx('mysql:host=localhost; dbname=techsmex; charset=utf8mb4', 'root', '');
And I'm getting the error:
could not find driver
Do I need to install a driver from somewhere that doesn't come with EasyPHP?
In EasyPHP Devserver 16.1.1, the default configuration file for php (php.ini) has the PDO MySQL extension disabled by default.
You have to enable it and restart your server before you can connect to your database.
In order to do this,
Go to your EasyPHP Devserver Dashboard;
Stop your HTTP Server in case it is running;
Select the version you are using for PHP in the left panel;
Open the corresponding folder for your PHP.
In it, is your php.ini file. Open the file with your preferred text editor, and search for ;extension=php_pdo_mysql.dll
Simply remove the semicolon in the beginning so the extension gets activated upon restarting of the HTTP server. Go to your dashboard's main page, and restart the HTTP server.
I am facing some issue while starting Apache server via XAMPP. I have installed XAMPP Version 5.6.3.
When I start the Apache server from xampp control panel, an error message is displayed as shown below:
On clicking 'OK' button, another dialog box is displayed as shown:
The thing is I wanted to use OCI instead of mysql. so I have commented out the mysql extensions and uncommented the OCI extension in php.ini file.
The php_oci8_12c.dll file is the only file available in the extensions (ext) folder of php in xampp. Hence I included the line in the php.ini as shown in the above image.
Since then I am getting this error.
I have installed instant client 12.1 as well but no luck. I also tried copying the OCI.dll from instantclient_12_1 and pasting it in c:/xampp/php and c:/xampp/apache/bin. The error still persists.
Need help..
UPDATE: I removed other oracle paths in PATH of environment variables, keeping only the instantclient path. Now I am getting this error..
Well, I've installed XAMPP 1.8.2, PHP 5.4 and Apache 2.0, and I use php_oci8_11g.dll and works fine.
You are trying use php_oci8_12g.dll, I recommend you read this link http://www.oracle.com/technetwork/articles/dsl/technote-php-instant-12c-2088811.html with especifications for run oci12g.
I solved the issue after stuck 2-3 days .
Before follow steps Some things to remmember .
1- I am using win 8.1 64 bit .
2- Using Xampp 5.6.31 32 bit .
3- Using instaclient 12.2.0.1 64 bit (Because my win 8.1 is 64 Bit ) .
Now steps are below -
Step 1 - Download xampp 5.6.31 32 bit and install it .
Step 2 - Download and install oracle 11g R2
Step 3 - Download and install OTN (oracle instaclient 12.2.0.1 )
Extract all files in any drive in my case i have extract in C:\oracle\instaclient12.2.0.1
Add (C:\oracle\instaclient12.2.0.1 ) it to the path variables of the system. and also add new variable under variable of system with name TNS_ADMIN and put same path (C:\oracle\instaclient12.2.0.1 ) in its value .
Its time to set PHP.INI here uncomment following (see image below)
PHP.ini setup
Copy 3 files from C:\oracle\instaclient12.2.0.1 oci.dll,oraociei12.dll and oraons.dll to xampp apache\bin . by this step Unable to load dynamic library issue has been resolved .
Unable to load dynamic library issue solution
Now restart Apache on xampp and check info.php on browser . OCI8 module will appear there enable .
Enjoy !!!.
I solved the issue. The problem was that I was trying to use a 64 bit DLL(php_oci8_12g.dll) in a 32 bit PHP. I downloaded a 32 bit instantClient and it works now! :-)
instantclient-basic-nt-12.1.0.2.0.zip
I had a problem related to OCI8 and XAMPP for days in a row, the problem was shown as:
Fatal error: Call to undefined function oci_connect()
I was able to correct it using the php that comes by default with XAMPP. I'm using windows 10 64 bits as well, but used xampp-win32-7.3.2-0-VC15 (php 7.3.2). To summarize, I was able to get a correct configuration by doing everything with 32 bits versions (except the o.s). The full story and how I've done it:
If you go to your xampp/php directory through cmd, in my case it was "C:\xampp\php", and start the php by the simple command "php" it will probably show what dlls are not being found in the etc folder or which of those are not Win 32 compatible. If you get this problem, you will not be able to see the OCI8 page when opening a phpinfo() page:
If that's the case, with win 32 compatibility problems or not finding the dlls that you are certain are there, you should unistall XAMPP and reinstall it using a x32 version. The phpinfo page will show x86 Architecture. Remember to remove in the path variables any source that miss locate your php in use, the point here is to use the one given by default in XAMPP. If you need by any reason to use another php installation, remember to use x86 architecture.
If you need an updated OCI8 dll you can download it on https://pecl.php.net/package/oci8 , but remember to check the Thread Safety compatibility, you can find it on your phpinfo page as well. In my case it was enough to use the one provided by XAMPP.
After this, you have to enable the extension:
extension=oci8_12c
in the php.ini configuration file. It was enough for me to enable only this one, although some people suggests to also enable extension=pdo_oci. My suggestion is to try this only if you failed to install with the path here shown. It's also good to check if you are set in the correct path regarding the extensions, in my case:
extension_dir="C:\xampp\php\ext"
After this, you have to download the Oracle Instant Client. Since you are using x86 architecture (you must use this one), you need to find a 32-bit version of the OIC, but is also important to check which one is compatible with the extension you uncommented. In my case, of oci8_12c, it was instantclient-basic-nt-12.2.
The final step is to unzip it to a folder, like "C:\instantclient_12_2" and add it to the path variables of the system.
Reload apache and check if the OCI8 is shown correcly.