Tuesday, March 12, 2013

Connecting Oracle 10g express using PHP and Apche on Scientific Linux 6.2


Installed Oracle 10g Express on Scientific Linux 6.2 before

http://wowmoron.blogspot.in/2012/12/install-oracle-10g-express-on.html


Ok installed PHP and Apache on Scientific Linux 6.2 before

http://wowmoron.blogspot.in/2012/11/install-apachemysqlphp-lamp-on-centos.html

Now connecting Oracle 10g express using PHP

all we have to do basically installing zend server community edition

so the steps are

create a file

/etc/yum.repos.d/zend.repo



[Zend]
name=zend-server
baseurl=http://repos.zend.com/zend-server/6.0/rpm/$basearch
enabled=1
gpgcheck=1
gpgkey=http://repos.zend.com/zend.key

[Zend_noarch]
name=zend-server - noarch
baseurl=http://repos.zend.com/zend-server/6.0/rpm/noarch
enabled=1
gpgcheck=1
gpgkey=http://repos.zend.com/zend.key

save the file and close


yum install zend-server-php-5.3



after this

nano /var/www/html/database.php


  
&lt?php

    $conn = oci_connect("hr", "your_hr_password", "127.0.0.1/XE");

    $stid = oci_parse($conn, "select last_name, salary from employees");
    oci_execute($stid);

    $nrows = oci_fetch_all($stid, $results);

    echo "&lthtml>&lthead>&lttitle>Oracle PHP Test&lt/title>&lt/head>&ltbody>";
    echo "&ltcenter>&lth2>Oracle PHP Test&lt/h2>&ltbr>";
    echo "&lttable border=1 cellspacing='0' width='50%'>\n&lttr>\n";
    echo "&lttd>&ltb>Name&lt/b>&lt/td>\n&lttd>&ltb>Salary&lt/b>&lt/td>\n&lt/tr>\n";

    for ($i = 0; $i &lt $nrows; $i++ ) {
      echo "&lttr>\n";
      echo "&lttd>" . $results["LAST_NAME"][$i] . "&lt/td>";
      echo "&lttd>$" . number_format($results["SALARY"][$i], 2). "&lt/td>";
      echo "&lt/tr>\n";
    }

    echo "&lttr>&lttd colspan='2'> Number of Rows: $nrows&lt/td>&lt/tr>&lt/table>";
    echo "&ltbr>&ltem>If you see data, then it works!&lt/em>&ltbr>&lt/center>&lt/body>&lt/html>\n";

  ?>

(ok as I can not use opening tag and closing tag in this blog I used > and < instead)

save the file and close

open your browser

localhost/database.php

you should see data and you are done



No comments:

Post a Comment