User Tools

Site Tools


kurs:hrdb.php

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
kurs:hrdb.php [2008/12/17 11:22]
mh
kurs:hrdb.php [2014/09/10 21:22] (current)
Line 1: Line 1:
 +<​code>​
 +<?php
 +abstract class HRDB {  //abstract only as a demonstration
 + 
 +  function connect() {
 +  global $db;
 +  if (!$db = @oci_pconnect('​hr',​ '​hr',​ '​orcl11'​)) {
 +    print "<​pre>";​
 +    print_r(oci_error());​
 +    print "</​pre>";​
 + exit;
 +    }
 +  }
 +  ​
 +  function db_select($sql,​ $bp) {
 +  global $db;
 +    ​
 + if (!$db) {$this->​connect();​}
 +
 +    $q = oci_parse($db,​ $sql);
 +    foreach ($bp as $param => $value) {
 +   oci_bind_by_name($q,​ $param, $value, 32 );
 + }
 +    ​
 + $r = oci_execute($q,​ OCI_DEFAULT);​
 +    $rows = oci_fetch_array($q,​ OCI_ASSOC);
 + return $rows;
 +  }
  
 + ​function db_insert($sql,​ $bp) {
 +  global $db;
 +    ​
 + if (!$db) {$this->​connect();​}
 +
 +    $q = oci_parse($db,​ $sql);
 +    foreach ($bp as $param => $value) {
 +   oci_bind_by_name($q,​ "​p_$param",​ $value, 32 );
 + }
 +    oci_bind_by_name($q,​ ":​ret_id", ​  ​$rowid,​ 32);
 + $r = oci_execute($q,​ OCI_DEFAULT);​
 +
 + return $rowid;
 +  }
 +
 +  ​
 +  function dump() {    ​
 +    print_r($this);​
 +  }
 +
 +}
 +
 +?> 
 +</​code>​