Knowledge Base Nr: 00179 combobox.txt - http://www.swe-kaiser.de

Downloads:

PHP: Oracle datenbank auslesen (OCI)

  
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
<title>Kombobox aus Datenbank füllen</title>
</head>

<body>

<center>

<?
$doselect = $_GET["doselect"];
if (!$doselect)
$doselect = "select * from cat";

$dosel = $_GET["dosel"];

#echo("<h2>dosel: $dosel doselect: $doselect</h2>\n");

if ($dosel == "")
{
$results = "<option selected> -- no result -- </option>\n";
}
else
{
# datenbankzugriff
$user = "***";
$pwd = "***";

if (!$_GET["direct"])
$dns = "or2000-tcp";
else
$dns = "(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)
(HOST = 153.95.240.244)(PORT=1526)))
(CONNECT_DATA=(SID = ORCL)
))";

echo("<h3>datenbankzugriff: $user/$pwd@$dns</h3>\n");

#datenbankfunktion ausführen (werte einlesen von stored procedure)
$conn = OCILogon ($user, $pwd, $dns);
$stmt = OCIParse($conn, "BEGIN DUMMY2(:val1, :val2, :val3, :val4); END;");

OCIBindByName($stmt, ":val1", &$val1, 100);
OCIBindByName($stmt, ":val2", &$val2, 100);
OCIBindByName($stmt, ":val3", &$val3, 100);
OCIBindByName($stmt, ":val4", &$val4, 100);
OCIExecute($stmt);

$results = "<option>$val1</option>\n";
$results .= "<option>$val2</option>\n";
$results .= "<option>$val3</option>\n";
$results .= "<option>$val4</option>\n";

echo "<h3>query: $doselect</h3>\n";

#select ausführen
$query = $doselect;

$stid = OCIParse($conn, $query);
OCIExecute($stid);
OCISetPrefetch($stid, 100);

echo("<table border=\"0\" cellspacing=\"4\" cellpadding=\"5\">\n");

$ncols = OCINumCols($stid);
echo "<tr>\n";
for ($i = 1; $i <= $ncols; $i++)
{
$column_name = OCIColumnName($stid, $i);
$column_type = OCIColumnType($stid, $i);
$column_size = OCIColumnSize($stid, $i);
echo "<th>$column_name ($column_type($column_size))</th>\n";
}
echo "</tr>\n";

while ($succ = OCIFetchInto($stid, $row, OCI_RETURN_NULLS))
{
echo "<tr>\n";
foreach ($row as $item)
{
echo "<td bgcolor=\"#FFFF80\">$item</td>\n";
}
echo "</tr>\n";
}

#datenbank beenden
OCIFreeStatement($stmt);
OCILogoff($conn);
}
?>
</table>

<h1>Kombobox aus Datenbank füllen</h1>

<p>diesen text modifizieren!</p>

<form action="combobox.php" method="get" align="center">
<select name="dbsel" size="6">
<option>1: or2000</option>
<option>2: weinheim dslxs09</option>
<option>3: weinheim dslxs01</option>
<option>4: oberwihl obwlxs01</option>
<option selected>5: laudenbach 113</option>
</select>
direkt<input type="checkbox" name="direct" value="1" checked>
<select name="result" size="4">
<? echo($results); ?>
</select>
<br>Select :
<? echo("<input name=\"doselect\" size=\"40\" value=\"$doselect\">\n"); ?>
<input type="submit" name="dosel" value="query">
</form>

<hr>
<p>noch ein text zum modifizieren!</p>

</center>

</body>
</html>