Connect php with Oracle DB

Discussion of testing theory and practice, including methodologies (such as TDD, BDD, DDD, Agile, XP) and software - anything to do with testing goes here. (Formerly "The Testing Side of Development")

Moderator: General Moderators

Connect php with Oracle DB

Postby hamdan » Wed Mar 21, 2012 4:55 am

hi every body

my problem is very huge :banghead: :(
it's first time to use php language ( powerful language) i want to connect php with oracle db 10 on remote server.

operating system : windows xp sp3
DataBase :remote oracle db 10.2
Apache Server : Apache 2.2
PHP : 5.3
Oracle Client Instant : instantclient_11_2

i'm following those setps ():
-------------------------------------------------------------------------------------------------------------------------------------------
Installing Apache HTTP Server on Windows
The following procedure describes how to install the Apache HTTP Server on Windows
Download the Apache HTTP Server Windows binaries from
http://www.apache.org/dist/httpd/binaries/win32/. The release used in this installation
is Apache HTTP Server 2.0.59, and the downloaded file is named apache_2.0.59-win32-x86-no_ssl.msi.
2. Double click the downloaded file apache_2.0.59-win32-x86-no_ssl.msi.
3. Follow the Apache HTTP Server installation wizards. You should select to install Apache HTTP Server
for All Users, on Port 80, because the only for the Current User alternative will clash with Oracle
Database Express Edition’s default port 8080.
-------------------------------------------------------------------------------------------------------------------------------------------
Installing PHP With OCI8 on Windows
This section discusses the PHP Windows MSI installer. PHP is also installable from ZIP files. Refer to the
PHP documentation for those steps.
To install OCI8 on Windows, the Oracle 10g or 11g client libraries are required. These can be from a
local database, or from Oracle Instant Client. Apache is also required.
PHP binaries for Windows come in thread-safe and non- thread-safe bundles. The non- thread-safe
version requires the web server to be in a non-threaded mode.
Installing OCI8 Using a Local Database on Windows
To install OCI8 on Windows XP Professional Edition:
1. Download the PHP 5.2.7 installer package from http://www.php.net/downloads.php.
2. Double click on the downloaded file php-5.2.7-win32-installer.msi. The PHP Windows installer starts.
3. Click Next on the Welcome screen. The license agreement is displayed.
4. Accept the license agreement by checking the box and click Next.
5. Select the installation location of the PHP files and click Next.
6. In the Web Server Setup screen, select the web server you want to use. This installation uses the
Apache 2.0 module option. Select Apache 2.0.x Module and click Next.
7. In the Apache Configuration Directory screen, select the location of the Apache conf directory and click
Next. For Apache 2.0, the standard configuration directory is C:\Program Files\ApacheGroup\Apache2\
conf\
8. In the Choose Items to Install screen, scroll down to the Extensions branch and add the Oracle 8
extension to the installation. Click Next.
9. In the Ready to Install PHP 5.2.7 screen, click Install. The installer installs PHP.
10. A dialog is displayed asking whether you want to configure Apache. Click Yes.
11. A confirmation message is displayed to confirm that the httpd.conf file has been updated. Click OK.
12. A confirmation message is displayed to confirm that the mime.types file has been updated. Click OK.
13. A final confirmation message is displayed to confirm that the PHP installation has completed. Click
Finish.
14. Restart Apache with Start > Programs > Apache HTTP Server 2.0.59 > Control Apache
Server > Restart. This opens a console window showing any error messages. Errors may also
be recorded in C:\Program Files\Apache Group\Apache2\logs\error.log. If you have errors,
double check your httpd.conf and php.ini files, and correct any problems.
-------------------------------------------------------------------------------------------------------------------------------------------
Installing OCI8 with Instant Client on Windows
After installing the Apache HTTP Server, you can install Oracle Instant Client and configure PHP to
connect to a remote Oracle database.
To install:
1. Download the Instant Client Basic package for Windows from the Instant Client page on the Oracle
Technology Network:
http://www.oracle.com/technology/tech/o ... lient.html
The Windows 32 bit ZIP file is called instantclient-basic-win32-11.1.0.6.0.zip and is around 42 MB in
size.
If you need to connect to Oracle 8i, then install the Oracle 10g Instant Client.
On some Windows installations, to use Oracle 10g Instant Client you may need to locate a copy of
msvcr71.dll and put it in your PATH.
2. Create a new directory (for example, C:\instantclient_11_1). Unzip the downloaded file into the new
directory.
3. Edit the Windows environment and add the location of the Oracle Instant Client files,
C:\instantclient_11_1, to the PATH environment variable, before any other Oracle directories. For
example, on Windows XP, use Start > Settings > Control Panel > System > Advanced > Environment
Variables, and edit PATH in the System Variables list.
If you are using a tnsnames.ora file to define Oracle Net connect names (database aliases), copy the
tnsnames.ora file to C:\instantclient_11_1, and set the user environment variable TNS_ADMIN to
C:\instantclient_11_1.
Set any other required Oracle globalization language environment variables, such as NLS_LANG. If
nothing is set, the default local environment is used. See the Globalization chapter, for more
information on globalization with PHP and Oracle.
Unset any Oracle environment variables that are not required, such as ORACLE_HOME and
ORACLE_SID.
4. Install PHP following the steps in the previous section, Installing OCI8 Using a Local Database on
Windows.
5. Restart the Apache HTTP Server.
-----------------------------------------------------------------------------------------------------------------------------

Syntax: [ Download ] [ Hide ]
<?php
phpinfo();
?>
 

it 's appear this page
oci8
OCI8 Support enabled
Version 1.4.7
Revision $Revision: 321634 $
Active Persistent Connections 0
Active Connections 0
Oracle Run-time Client Library Version 0.0.0.0.0
Oracle Instant Client Version 11.2
Temporary Lob support enabled
Collections support enabled

Directive Local Value Master Value
oci8.connection_class PHP_INI_ALL PHP_INI_ALL
oci8.default_prefetch 100 100
oci8.events Off Off
oci8.max_persistent -1 -1
oci8.old_oci_close_semantics Off Off
oci8.persistent_timeout -1 -1
oci8.ping_interval 60 60
oci8.privileged_connect Off Off
oci8.statement_cache_size 20 20









-------------------------------
when i 'm use this code to connect to oracle db

Syntax: [ Download ] [ Hide ]
<?$conn = oci_connect($username,$pass,'ip address/db name');?>


or this
Syntax: [ Download ] [ Hide ]
<? $db = '(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)
(HOST = 192.168.26.33)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = REG)))'
;
$conn = oci_connect(($username,$pass, $db);
?>
 




when execute it this message is appear:
Warning: oci_connect(): OCIEnvNlsCreate() failed. There is something wrong with your system - please check that PATH includes the directory with Oracle Instant Client libraries

PATH on windows enviroment is set true .
Any Help Plz???
hamdan
Forum Newbie
 
Posts: 1
Joined: Wed Mar 21, 2012 3:32 am

Re: Connect php with Oracle DB

Postby rianfu21 » Sat May 19, 2012 8:47 am

The Oracle database is a database management system developed and sold by Oracle Corporation. It is used by many large corporations. PHP is a server-side scripting language used to create dynamic Web pages, often based on data stored in a database. While the most common database used with PHP is MySQL, PHP includes the OCI8 extension that allows you to access Oracle Database 11g, 10g, 9i and 8i Soy Candles.

Instructions

1 Create a new PHP file in an editor. For example, type:

nano oracle.php

2 Create a connection to the Oracle database using the OCI extension by passing the username, password and database. For example, type:

<?php

$db = oci_connect("username", "password", "machine.domain/DATABASE");

if (!$db) die("Error connecting to Oracle database: " . oci_error());

echo "Successfully connected to Oracle database!";

?>

3 Exit the editor to save the program. Launch the program in a browser to test if the connection to the Oracle database was successful.
rianfu21
Forum Newbie
 
Posts: 1
Joined: Sat May 19, 2012 8:15 am


Return to Testing

Who is online

Users browsing this forum: No registered users and 1 guest