Location: PHPKode > scripts > iOracleDriver > OracleDriver.class.php
<?php
/**
 *  support/OracleDriver.class.php
 * @author Emmanuel Arana Corzo <hide@address.com>
 * @version 0.1.1
 * @documentation This class only works as interpreter,
 *                works directly with the database.
 */

 if(!defined("__SUPPORT_ORACLEDRIVER_CLASS__")) {
   define("__SUPPORT_ORACLEDRIVER_CLASS__", 0x010101);
   

   
     class OracleDriver {
       //Atributes
       private $tnsName;              #This is the service name registered in Oracle client
       private $user;                 #This is the user name
       private $pass;                 #This is the user's password
       private $conn;                 #This is the database connection variable
       private $connectionStatus;     #Is already connected?
     
       //Operaciones
       /*
        It is the class constructor. Inits the connection with the database.
        The parameters are:
        -tns (Oracle's service name)
        -usr (User name)
        -pwd (password)
       */
       public function __construct($tns = "produccion", $usr = "userprod", $pwd = "userprod") {
         $this->connectionStatus = false;
         $this->connect($tns, $usr, $pwd);
       }
       /*
        It is the class destructor, free the connections
       */
       public function __destruct() {
         $this->close();
       }
       /*
        Connects with the database (opens a connection port between the oracle server and the apache server).
        The parameters are:
        -tns (It is the Oracle's database service (tns as well))
        -usr (It is the username)
        -pwd (It is the user's password)
       */
       public function connect($tns = "produccion", $usr = "userprod", $pwd = "userprod") {
         $this->setTns($tns);
         $this->setUser($usr);
         $this->setPass($pwd);
         if($this->conn = oci_connect($this->user, $this->pass, $this->tnsName)) {
           $this->connectionStatus = true;
         }
       }
       /*
        Closes the connection port with the database
       */
       public function close() {
         oci_close($this->conn);
         unset($this->conn);
         $this->connectionStatus = false;
       }
       /*
       Executes a PL/SQL instance, and returns an statement, that works to
       catch in the constructor of the OracleRecordset class
       The parameters are:
       -sql (This is the sql instance, that will be executed)
       */
       public function &execute($sql) {
         if($rsQry = $this->parse($sql)) {
           oci_execute($rsQry);
           return $rsQry;
         }
         else { return 0x00; }
       }
       /*
       Stablish a commit of all the transactions
       */
       public function commit() {
         return oci_commit($this->conn);
       }
       /*
       Stablish a service name
       */
       public function setTns($tns) {
         $this->tnsName = ((empty($tns)) ? "orahome" : $tns);
       }
       /*
       Stablish a name for the user (this will works as schema as well)
       */
       public function setUser($usr) {
         $this->user = ((empty($usr)) ? "system" : $usr);
       }
       /*
       Stablish a new password for a user in the schema
       */
       public function setPass($pwd) {
         $this->pass = ((empty($pwd)) ? "manager" : $pwd);
       }
       public function getTns() {
         return $this->tnsName;
       }
       public function getUser() {
         return $this->user;
       }
       public function getPass() {
         return $this->pass;
       }
       /*
       Verifies the kind of query to be realized
       */
       private function parse($sql) {
         return oci_parse($this->conn, $sql);
       }
       /*
       This will give us the connection status...
       */
       public function getConnStatus() {
         return $this->connectionStatus;
       }
     }  /** End of OracleDriver */

 }

?>
Return current item: iOracleDriver