Accessing Oracle from PHP

This document describes how to access an Oracle database from PHP.

Install

  • php5-dev
  • php-pear
  • zip
  • unzip
  • libaio1

Download the instant client basic and sdk (2 files) from www.oracle.com . Note that the client version is at most 2 major releases downwards compatible with the server version, so you cannot use client version 11 on a server with version 8. Create a new directory /opt/oracle and unzip the 2 files which you have downloaded.

Then run these commands:

ln -s instantclient_10_2 instantclient
cd instantclient
pwd > /etc/ld.so.conf.d/oracle.conf
ldconfig
ln -s libclntsh.so.10.1 libclntsh.so
ln -s libocci.so.10.1 libocci.so
pecl install oci8

The version numbers may have to be adjusted according to your needs, but leave oci8 as-is.

The last command will ask a question. Answer with:

1
shared,instantclient,/opt/oracle/instantclient
<enter>

Then run these commands:

echo "extension=oci8.so" > /etc/php5/apache2/conf.d/oracle.ini
echo "extension=oci8.so" > /etc/php5/cli/conf.d/oracle.ini
/etc/init.d/apache2 restart

To test the connection, I wrote the following code:

<?php

function do_oracle_query($query)
{
   $db = "(DESCRIPTION=
             (ADDRESS_LIST=
                (ADDRESS=
                   (PROTOCOL=TCP)
                   (HOST = <oracle_hostname>)
                   (PORT = <oracle_portnumber>)
                )
             )
             (CONNECT_DATA =
                (SID = <oracle_databasename>)
             )
          )";
   $db_conn = oci_connect("<oracle_username>", "<oracle_password>", $db);
   if (!$db_conn)
   {
      echo "Cannot connect to the database...\n";
      print_r(oci_error());
      return 0;
   }
   $stmt = oci_parse($db_conn, $query);
   oci_execute($stmt);
   $nrows = oci_fetch_all($stmt, $results);
   oci_free_statement($stmt);
   oci_close($db_conn);
   return $results;
}

function test_connection()
{
   $results = do_oracle_query("select SYSDATE from dual");
   if ($results === 0)
      return;
   $n = Count($results['SYSDATE']);
   if ($n == 0)
   {
      print "No results";
      return;
   }
   print $results['SYSDATE'][0];
}

test_connection();

?>

Note that <oracle_hostname>, <oracle_portnumber>, <oracle_databasename>, <oracle_username> and <oracle_password> need to be adjusted accordingly. The table "dual" used here is a fake table you can specify in Oracle SQL queries when you do not want to use any table for your query.

Accessing Oracle from PHP

Accessing oracle from PHP is a simple task. I, as a part time web developer in Jakarta - Indonesia, can do this quick. By doing some simple coding and testing, I can access oracle from all platform I created. This is much simpler than installing a oracle in your website :) So if you want to build a web with oracle, I suggest you to do this :)

imranuddin

I love the blog. Great post. It is very true, people must learn how to learn before they can learn. lol i know it sounds funny but its very true. . . best Mexican restaurants near me

imranuddin

You have done a great job. I will definitely dig it and personally recommend to my friends. I am confident they will be benefited from this site. facebook

شركة خدمات منزلية متميزة ورخيصه

What items should be loaded first? Your fully packed and properly labeled moving boxes should be loaded first into the rented truck. شراء اثاث مستعمل بالرياضStack them vertically and go higher and higher against the back of the moving vehicle. Make sure the heaviest boxes stay at the bottom and the lighter and more fragile ones go on the top.شركة نقل اثاث من الرياض الى الكويت - شركة نقل اثاث من الرياض الى الاردن

bfirstseo

Furniture move he majority of DIY home movers are really interested in knowing how to properly load their rented moving vehicles so that the entire storage space is utilized in the best possible way. نقل عفش بالرياض The main concern for families who have decided to move on their own still remains the danger of choosing a moving truck with insufficient space for their belongings. شركة شراء اثاث مستعمل بالرياض To complicate things further, even the right choice of a rental moving vehicle can easily turn out to be a serious problem if the loading process is not done the right way. And believe us, leaving prized possessions behind or being forced to make two trips are two moving scenarios you don’t really want to go through for various reasons.

Cleaning carpets

Services available: - Combating and eradication of insects and Rumah rodents. - The eradication of rats and mil White. - Cleaning carpets, mattresses. - Washing and cleaning curtains and sofas. شركات مكافحة حشرات بجدة شركات مكافحة حشرات بمكة شركات مكافحة حشرات بالخرج شركات مكافحة الحشرات بالاحساء شركة مكافحة حشرات بحائل

Ritz Carlton Washington DC wedding photographers

Those who have won the most rodneybailey are listed at the top. Although based in Washington, DC, Photographers are happy to travel to any wedding destination—so be sure to look outside your home region, too. Your perfect photographer is just a few clicks away.Ritz Carlton Washington DC wedding photographers

hardwell032

I would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well. In fact your creative writing abilities has inspired me to start my own BlogEngine blog now. Really the blogging is spreading its wings rapidly. Your write up is a fine example of it. http://rainbowpages.fr/Astuce-Criminal-Case/

martingarix229

Hi there, I found your blog via Google while searching for such kinda informative post and your post looks very interesting for me. facebook

ecNyO MuM GVIb

viagra tablets in delhi is there a minimum age for viagra buy viagra real quand viagra generique no rx brand viagra stopper l'effet du viagra si perdoret viagra el significado de viagra my canadian pharmacy viagra find generic viagra cheapest place to buy real viagra combining viagra cialis typical viagra prices manforce viagra buy online viagra sale from canadian company mio marito usa viagra order viagra online in south africa viagra eladГі szombathely generic viagra costco generic viagra online from us real viagra pills buy viagra australia generic viagra new zealand spinnengift statt viagra where can i buy viagra in abuja che effetto fa il viagra viagra finland buy sildenafil online Montgomery works like viagra cuanto cuesta viagra uruguay comprar viagra generico en europa si puo prendere cialis e viagra insieme is amlodipine besylate like viagra el viagra y la hipertensiГіn generic viagra super generic viagra new au viagra online apotheke sildenafil buy Rockford

slimming bathing suits for plus size women dpd

Plus Size Swimwear | Swimsuits for Real Women swimsuits1 com - More info! swimsuit with underwire bra plus sizemaxine bathing suits plus sizewomen's long bathing suitsfull figured bikini swimwearcheap womens plus size swimwearplus swimwear cheapfull figured swimsuittankini and swim shortsdd cup one piece swimwearwomen's size bathing suitslongitude swim dressesplus size swim dresses 2013plus size swimsuit tops with underwiresize 16 swimsuits with underwiretankini size 20 swimsuits1 com/ > large women swimsuits swimsuits1 com/Plus-Size-Cover-Ups-Swimwear-Cover-Ups-D > crochet skirt beach cover up swimsuits1 com/ > swim suites for women swimsuits1 com/Plus-Size-Swimwear > bathing suit plus size women swimsuits1 com/Shop-All-Swimwear > new style swimsuits swimsuits1 com/Designers-Swimsuits-L > swimwear designers swimsuits1 com/ > plus size strapless swimsuits swimsuits1 com/High-Waist-Swimwear-Bikinis-D > 2 piece swimsuits with high waist bottoms swimsuits1 com/ > suit swimwear swimsuits1 com/Plus-Size-Clearance-Swimwear-Sale > cheap cover ups for bathing suits swimsuits1 com/Shore-Club-Beachy-Keen-H-Back-Plus-Size-Swimdress > beachy keen swimwear swimsuits1 com/Fit-Solutions-Swimwear > swimsuit solutions swimsuits1 com/Plus-Size-Chlorine-Resistant-Swimwear-Aquabelle > h20wear swimsuits1 com/Long-Torso-Swimwear-Design-Fit-Finder > long torso body shaper swimsuits1 com/ > best plus size swimwear sites

ge logiq p6 brochure

endorectal ultrasound Philips X7-2 new and used medical equipment abdominal echogram hitachi eub 405 plus 4ufieldhockey com:11751 klimindoor com:39589 seagreensusa com:26781 thriveorfail com:41992 black7comics com:26109 seagreensusa com:27721 edgeymedia com:17708 klimindoor com:32443 seagreensusa com:30714 paulhewittbasketballcamp com:29020 thsfda com:22373 briarskin com:29812 briarskin com:19122 seagreensusa com:33281 4ufieldhockey com:20557 klimindoor com:10192 bellartesingers com:37454 seagreensusa com:35596 attributionnoderivativestv com:18987 dvfreak com:21574 klimindoor com:17639 seagreensusa com:17198 thsfda com:26571 mutualevantecafemax com:11098 klimindoor com:31269 mutualevantecafemax com:37470 mutualevantecafemax com:12418 withinisugly com:14019 maestriaspanama com:33500 bellartesingers com:25666 attributionnoderivativestv com:36208 4ufieldhockey com:25489 mutualevantecafemax com:41880 thriveorfail com:30974 mutualevantecafemax com:20543 klimindoor com:40441 seagreensusa com:17887 maestriaspanama com:20037 verduomo com:35908 mutualevantecafemax com:39376 withinisugly com:18295 cancomsolutions com:24744 cancomsolutions com:23249 withinisugly com:26443 seagreensusa com:11938 atl systems vivid dvd sales buy a dc-3 3d ultrasound cost in india ssa 530a alokaultrasounds com:38201 alokaultrasounds com:35767 alokaultrasounds com:17857 alokaultrasounds com:39468 alokaultrasounds com:29420 alokaultrasounds com:40085 alokaultrasounds com:12268 alokaultrasounds com:14232 alokaultrasounds com:17742 alokaultrasounds com:39343 alokaultrasounds com:24899 alokaultrasounds com:16587 alokaultrasounds com:32552 alokaultrasounds com:19215 alokaultrasounds com:24814 alokaultrasounds xyz:27454 alokaultrasounds xyz:39874 alokaultrasounds xyz:22208 alokaultrasounds xyz:32089 alokaultrasounds xyz:39967 alokaultrasounds xyz:12806 alokaultrasounds xyz:27627 alokaultrasounds xyz:23782 alokaultrasounds xyz:39566 alokaultrasounds xyz:24351 alokaultrasounds xyz:14818 alokaultrasounds xyz:33991 alokaultrasounds xyz:30913 alokaultrasounds xyz:27527 alokaultrasounds xyz:14153 esaoteultrasound com:17160 esaoteultrasound com:12629 esaoteultrasound com:23520 esaoteultrasound com:27283 esaoteultrasound com:24297 esaoteultrasound com:14349 esaoteultrasound com:41499 esaoteultrasound com:40448 esaoteultrasound com:42153 esaoteultrasound com:29230 esaoteultrasound com:12030 esaoteultrasound com:23547 esaoteultrasound com:10739 esaoteultrasound com:36353 esaoteultrasound com:33317 esaoteultrasound xyz:34745 esaoteultrasound xyz:31963 esaoteultrasound xyz:40767 esaoteultrasound xyz:14328 esaoteultrasound xyz:32354 esaoteultrasound xyz:39405 esaoteultrasound xyz:35529 esaoteultrasound xyz:32592 esaoteultrasound xyz:17635 esaoteultrasound xyz:30701 esaoteultrasound xyz:35679 esaoteultrasound xyz:31962 esaoteultrasound xyz:27207 esaoteultrasound xyz:10047 esaoteultrasound xyz:14715 philipsultrasounds com:25722 philipsultrasounds com:24361 philipsultrasounds com:34473 philipsultrasounds com:20027 philipsultrasounds com:34313 philipsultrasounds com:38703 philipsultrasounds com:31316 philipsultrasounds com:36641 philipsultrasounds com:10705 philipsultrasounds com:17296 philipsultrasounds com:38277 philipsultrasounds com:12629 philipsultrasounds com:37594 philipsultrasounds com:32843 philipsultrasounds com:22444 philipsultrasounds xyz:35543 philipsultrasounds xyz:37721 philipsultrasounds xyz:38049 philipsultrasounds xyz:36185 philipsultrasounds xyz:33910 philipsultrasounds xyz:24241 philipsultrasounds xyz:22544 philipsultrasounds xyz:18456 philipsultrasounds xyz:35158 philipsultrasounds xyz:26651 philipsultrasounds xyz:18365 philipsultrasounds xyz:29701 philipsultrasounds xyz:29142 philipsultrasounds xyz:17823 philipsultrasounds xyz:32539 siemensultrasounds com:31447 siemensultrasounds com:24898 siemensultrasounds com:37271 siemensultrasounds com:13784 siemensultrasounds com:28103 siemensultrasounds com:39909 siemensultrasounds com:30813 siemensultrasounds com:17675 siemensultrasounds com:13217 siemensultrasounds com:33222 siemensultrasounds com:20389 siemensultrasounds com:15033 siemensultrasounds com:18290 siemensultrasounds com:24056 siemensultrasounds com:27366 siemensultrasounds xyz:40191 siemensultrasounds xyz:38993 siemensultrasounds xyz:25785 siemensultrasounds xyz:41823 siemensultrasounds xyz:13240 siemensultrasounds xyz:27874 siemensultrasounds xyz:29573 siemensultrasounds xyz:30546 siemensultrasounds xyz:11935 siemensultrasounds xyz:12012 siemensultrasounds xyz:25740 siemensultrasounds xyz:12801 siemensultrasounds xyz:23950 siemensultrasounds xyz:24304 siemensultrasounds xyz:18226 toshibultrasound com:22655 toshibultrasound com:33956 toshibultrasound com:27718 toshibultrasound com:32802 toshibultrasound com:24117 toshibultrasound com:23870 toshibultrasound com:32520 toshibultrasound com:24307 toshibultrasound com:19123 toshibultrasound com:35185 toshibultrasound com:41153 toshibultrasound com:29440 toshibultrasound com:40785 toshibultrasound com:34530 toshibultrasound com:35087 toshibultrasound xyz:11571 toshibultrasound xyz:26976 toshibultrasound xyz:21621 toshibultrasound xyz:33131 toshibultrasound xyz:41471 toshibultrasound xyz:23577 toshibultrasound xyz:17538 toshibultrasound xyz:17368 toshibultrasound xyz:15302 toshibultrasound xyz:39778 toshibultrasound xyz:22644 toshibultrasound xyz:15144 toshibultrasound xyz:12480 toshibultrasound xyz:13169 toshibultrasound xyz:17623

Hacking issues are so common

Hacking issues are so common these days. It is just easy by changing the variables of the program. - Bath Planet