--- On Mon, 11/24/08, Chris <[EMAIL PROTECTED]> wrote:
> From: Chris <[EMAIL PROTECTED]>
> Subject: Re: [PHP-DB] works under mysql 5 but not under Oracle 11g1
> To: [EMAIL PROTECTED]
> Cc: php-db@lists.php.net
> Date: Monday, November 24, 2008, 6:41 AM
> Fred Silsbee wrote:
>
> > while ($newArray = oci_fetch_assoc($result)) {
> > foreach ($fields as $field){
> ${$field} = $newArray[$field]; // values not
> making it into variable
> > }
>
>
> print_r($newArray);
>
> what is here?
>
> Oracle uppercases all fields, tablenames by default (per
> sql spec).
>
> -- Postgresql & php tutorials
> http://www.designmagick.com/
here is the whole thing:
<?php
$db = "(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SID = LMKIIIGDNSID)
)
)";
// oci_internal_debug(1); // turn on tracing
// $conn = oci_connect("/", "", null, null, OCI_SYSDBA);
// if ($conn=oci_connect('hr', 'hr','LMKIIIGDNSID'))
if ($conn=oci_connect('landon', 'rumprocella',$db))
{
echo "Successfully connected to Oracle.\n";
// OCILogoff($conn);
}
else
{
$err = OCIError();
echo "Oracle Connect Error " . $err['message'];
}
//construct a global variable for the form profile
$fields = array("fdate", "actype", "acid", "nlandings", "nhours");
///
// If the submit button has been pressed
if (isset($_POST['select'])){
displayDeleteForm();
}elseif(isset($_POST['delete'])){
deleteRecords();
} elseif(isset($_POST['insert'])){
insertRecord();
} elseif (isset($_POST['new'])){
displayEntryForm();
} else {
//default action
displayEntryForm();
}
function displayDeleteForm(){
//get $fields into the function namespace
global $fields;
global $conn;
/* Create and execute query. */
// $query = "select * from log_book_id";
// $result = mysql_query($query);
// Loop through each row, outputting the actype and name
echo <<<HTML
Pilots Logbook entries stored in mySQL Relational Database
under Redhat Fedora 8 Linux
<form action="{$_SERVER['PHP_SELF']}" method="post">
<table width="50%" align="center" border="1">
<tr>
<th>checked</th>
<th>log_id</th>
<th>fdate</th>
<th>actype</th>
<th>acid</th>
<th>nlandings</th>
<th>nhours</th>
</tr>
HTML;
//get log_book_id table information
$user = "select * from log_book_id";
$result = oci_parse($conn, $user);
$r = oci_execute($result);
//display log_book_id information
$count = 0;
while ($newArray = oci_fetch_assoc($result)) {
foreach ($fields as $field){
${$field} = $newArray[$field];
// print("$field<BR>");
}
// echo $newArray['actype'] . "<br>";
$log_id = $newArray['rowID'];
// $log_id = $newArray['LOG_ID'];
// print($log_id);
//note that we do not rely on the checkbox value as not all browsers
submit it
//instead we rely on the name of the checkbox.
echo <<<HTML
<TR>
<td>
<input type="checkbox" name="checkbox[$log_id]"
value="$rowID">Check to delete record
</td>
<TD>$log_id</TD>
<TD>$fdate</TD>
<TD>$actype</TD>
<TD>$acid</TD>
<TD>$nlandings</TD>
<TD>$nhours</TD>
</TR>
HTML;
} // while
echo <<<HTML
<tr>
<td colspan="7">
<input type="submit" name="delete" value="delete checked
items"/>
<input type="submit" name="new" value="New Log Entry" />
<input type="reset" name="reset" value="Reset Form" />
</td>
</tr>
</table>
</form>
HTML;
} //close function
// ................................................................. DELETE
// code from a book "Beg PHP and MySQL 5" by Gilmore
function deleteRecords(){
// Loop through each log_book_id with an enabled checkbox
if (!isset($_POST['checkbox'])){
return true;
}
//else
foreach($_POST['checkbox'] as $key=>$val){
$toDelete[] = $key;
}
//expand the array for an IN query
$where = implode(',', $toDelete);
$query = "DELETE FROM log_book_id WHERE log_id IN ($where)";
$result = oci_parse($query);
// Should have one affected row
if ((mysql_affected_rows() === 0) || !$result) {
echo "<p>There was a problem deleting some of the selected
items.</p><p>".mysql_error().'</p>';
exit();
} else {
echo "<p>The selected items were successfully deleted.</p>";
}
//direct the user back to the delete form
displayDeleteForm();
} //end function
function insertRecord(){
// Retrieve the posted log book information.
global $fields;
//add some very crude validation
foreach ($fields as $field){
if (empty($_POST[$field])){
$messages[] = "You must complete the field $field \r\n";
} else {
$dFields[$field] = mysql_real_escape_string(trim($_POST[$field]));
}
}
if (count($messages)>0) {
displayEntryForm($messages, $dFields);
exit();
}
//end validation
//get variables into the namespace
extract($dFields);
// Insert the log book information into the log book table
$query = "INSERT INTO log_book_id SET fdate='$fdate', actype='$actype',
acid='$acid', nlandings='$nlandings', nhours = '$nhours'";
$result = oci_query($query);
// Display an appropriate message
if ($result) {
echo "<p>Product successfully inserted!</p>";
}else {
echo "<p>There was a problem inserting the log book!</p>";
}
//direct the user back to the entry form
displayEntryForm();
}
function displayEntryForm($errorMessages=null, $dFields=null){
if (!empty($errorMessages)){
echo "<ul><li>".explode('</li><li>', $errorMessages) . "</li></ul>";
}
//sort out field values
global $fields;
foreach ($fields as $field){
if (isset($dFields[$field])){
${$field} = $dFields[$field];
} else {
${$field} = '';
}
}
echo <<<HTML
<form action="{$_SERVER['PHP_SELF']}" method="post">
<p>
Flight Date:<br />
<input type="text" size="20" maxlength="40" name="fdate"
value="$fdate" />
</p>
<p>
Aircraft Type:<br />
<input type="text" size="20" maxlength="40" name="actype"
value="$actype" />
</p>
<p>
Aircraft ID:<br />
<input type="text" size="20" maxlength="40" name="acid"
value="$acid" />
</p>
<p>
Number Landings:<br />
<input type="text" size="20" maxlength="40" name="nlandings"
value="$nlandings" />
</p>
<p>
Number Hours:<br />
<input type="text" size="20" maxlength="40" name="nhours"
value="$nhours" />
</p>
<button type="submit" name = "insert" value="Insert Row!"
style="color:maroon font:18pt Courier; font-weight:bold ">Insert Row
</button>
<button type="submit" name = "select" value="Show All!"
style="color:red font:18pt Courier; font-weight:bold ">Show All
</button>
<button type="submit" name = "delete" value="Delete Row!"
style="color:red font:18pt Courier; font-weight:bold ">Delete Row!
</button>
</form>
HTML;
} //end display function
?>
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php