User Tools

Site Tools


kurs:php_oo

Differences

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

Link to this comparison view

Next revision
Previous revision
kurs:php_oo [2009/11/19 16:08]
mh created
kurs:php_oo [2014/09/10 21:22] (current)
Line 1: Line 1:
 +<​code>​
 +<?php
  
 +include_once "​DB.php";​
 +
 +$dbo = new DB;
 +$dbo->​dbconnect();​
 +
 +$q = oci_parse($dbo->​db,​ "​select * from employees"​);​
 +
 +$r = oci_execute($q,​ OCI_DEFAULT);​
 +
 +print "​Return $r\n";
 +
 +$ncols = oci_num_fields($q);​
 +
 +for ($i = 1; $i <= $ncols; $i++) {
 +    $column_name ​ = oci_field_name($q,​ $i);    ​
 +    $trow[] = $column_name; ​   ​
 +}
 +$table[] = $trow;
 +
 +while ($row = oci_fetch_array($q,​ OCI_ASSOC+OCI_RETURN_NULLS)) {
 +  $table[] = $row;  ​
 +}
 +
 +$dbo->​print_table($table);​
 +?>
 +</​code>​
 +
 +<​code>​
 +<?php
 +
 +ini_set('​display_errors',​ 1);
 +
 +class DB {
 +  public $db;
 + 
 +  function dbconnect() {
 +    $this->​db = oci_connect('​hr',​ '​hr',​ '​orcl'​);  ​
 +  }  ​
 +
 +
 + ​function print_table($table) {
 + print "<​table border=1>​\n";​
 + ​foreach ($table as $row) {
 +  print "<​tr>"; ​
 +  foreach ($row as $cell) {
 +    if (!isset($cell)) {$cell = '​n/​a';​ } 
 +    print "<​td>​ $cell </td> ";
 +  }
 +  print "</​tr>​\n";​
 +  } 
 +
 + print "</​table>​\n";​
 + }
 +}
 +?>
 +</​code>​
 +
 +<​code>​
 +<?php
 +
 +require_once('​DB.php'​);​
 +
 +class DB_Error extends DB {
 +  function dbconnect() {
 +    parent::​dbconnect();​
 + if (!$this->​db) {print "​Problem\n";​ exit;}
 +  }
 +}
 +?>
 +</​code>​
kurs/php_oo.txt ยท Last modified: 2014/09/10 21:22 (external edit)