Creating a sample class

The following is the sample program using classes and objects.
In this program, a class is created and its member variable is
assigned a value.

<?php
class test
{
var $a;

function assign($val)
{
$this->a = $val;
}

function display()
{
echo “Value ” . $this->a;

}
}

$t = new test();
$t->assign(‘2000’);
$t->a= 3000;
$t->display();
?>

The output of the above program will be:

Value: 3000

Connecting Oracle with PHP

In some instances, we need to connect Oracle with PHP.
The following is the sample program that connects oracle with php and
fetches data from an oracle table.

<?php

$dbuser = “username”;
$dbpass = “password”;
$dbserver = “//servername”;

$c=OCILogon($dbuser, $dbpass, $dbserver);

if (!$c) {
$err = OCIError();
echo “Oracle Connect Error ” . $err[text];
}

$query =”SELECT * from employee”;
$res= OCIParse($c,$query);
OCI_Execute($res, OCI_DEFAULT);

while(OCIFetch($res)){

$emp_id = OCIResult($res, “EMP_ID”);
echo “Employee id: ” . $emp_id;
}

OCILogoff($c);
?>