User Tools

Site Tools


kurs:get_emp_by_name.php

Differences

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

Link to this comparison view

kurs:get_emp_by_name.php [2014/09/10 21:22]
kurs:get_emp_by_name.php [2014/09/10 21:22] (current)
Line 1: Line 1:
 +<​code>​
 +<?php
 +print "<​h2>​request</​h2>​\n";​
 +print_r($_REQUEST);​
 +print "<​br>​\n";​
 +printf("​First Name: %s<​br>​ Last Name: %s<​br>​\n", ​
 +  $_REQUEST['​first_name'​],​ $_REQUEST['​last_name'​]);​
  
 +$db = oci_connect('​hr',​ '​hr',​ '​orcl'​);​
 +$sql = "​select * from employees where 
 +    last_name = '"​. $_REQUEST['​last_name'​]. ​
 + "'​ and first_name = '"​. $_REQUEST['​first_name'​] ."'";​
 +
 +$sql2 = sprintf(
 +   "​select * from employees where 
 +     ​last_name ​ = '​%s'​ and
 + first_name = '​%s'", ​
 + $_REQUEST['​last_name'​], ​
 + $_REQUEST['​first_name'​]);​
 +  
 +$sql3 = 
 +   '​select * from employees where 
 +     ​last_name ​ = :last_name and
 + first_name = :​first_name';​
 +
 +print $sql3 . "<​br>";​
 +$q = oci_parse($db,​ $sql3);
 +oci_bind_by_name($q,​ ":​last_name",​ $_REQUEST['​last_name'​],​-1, ​
 +                 ​SQLT_CHR );
 +
 +oci_bind_by_name($q,​ ":​first_name",​ $_REQUEST['​first_name'​],​-1,​
 +                 ​SQLT_CHR );
 +   ​
 +$r = oci_execute($q,​ OCI_DEFAULT);​
 +
 +$table[] = oci_fetch_array($q,​ OCI_ASSOC+OCI_RETURN_NULLS);​
 +
 +print_table($table);​
 +
 +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>​
kurs/get_emp_by_name.php.txt ยท Last modified: 2014/09/10 21:22 (external edit)