works under mysql 5 but not under Oracle 11g1

works under mysql 5 but not under Oracle 11g1

am 24.11.2008 07:04:12 von Fred Silsbee

//construct a global variable for the form profile
$fields = array("fdate", "actype", "acid", "nlandings", "nhours");

problem down in while loop
... . . . . .
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 << Pilots Logbook entries stored in mySQL Relational Database
under Redhat Fedora 8 Linux












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]; // values not making it into variable

}

$rowID = $newArray['rowID'];

//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;

} // while
echo <<


checked rowID fdate actype acid nlandings nhours

Check to delete record
$rowID $fdate $actype $acid $nlandings $nhours

 
 




HTML;
} //close function







--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: works under mysql 5 but not under Oracle 11g1

am 24.11.2008 07:41:05 von dmagick

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/


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: works under mysql 5 but not under Oracle 11g1

am 24.11.2008 15:28:43 von Fred Silsbee

--- On Mon, 11/24/08, Chris wrote:

> From: Chris
> Subject: Re: [PHP-DB] works under mysql 5 but not under Oracle 11g1
> To: fredsilsbee@yahoo.com
> 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/

I am new to PHP and I was wondering if an array can contain dissimilar types

while ($newArray = oci_fetch_assoc($result)) {

surely a DB row might contain :

create table log_book_id ( log_id number primary key, fdate date, actype varchar2(16), acid varchar(16), nlandings number, nhours number);

insert into log_book_id values (logid.nextval, TO_DATE('08/12/1973','MM/dd/YYYY'),'C150','N5787G',1,1.8);






--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: works under mysql 5 but not under Oracle 11g1

am 24.11.2008 15:33:28 von Fred Silsbee

--- On Mon, 11/24/08, Chris wrote:

> From: Chris
> Subject: Re: [PHP-DB] works under mysql 5 but not under Oracle 11g1
> To: fredsilsbee@yahoo.com
> 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:


$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 << Pilots Logbook entries stored in mySQL Relational Database
under Redhat Fedora 8 Linux












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
");
}
// echo $newArray['actype'] . "
";
$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;

} // while
echo <<


checked log_id fdate actype acid nlandings nhours

Check to delete record
$log_id $fdate $actype $acid $nlandings $nhours

 
 




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 "

There was a problem deleting some of the selected items.

".mysql_error().'

';
exit();
} else {
echo "

The selected items were successfully deleted.

";
}
//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 "

Product successfully inserted!

";
}else {
echo "

There was a problem inserting the log book!

";
}
//direct the user back to the entry form

displayEntryForm();
}

function displayEntryForm($errorMessages=null, $dFields=null){
if (!empty($errorMessages)){
echo "";
}

//sort out field values
global $fields;
foreach ($fields as $field){
if (isset($dFields[$field])){
${$field} = $dFields[$field];
} else {
${$field} = '';
}
}

echo <<


Flight Date:

value="$fdate" />



Aircraft Type:

value="$actype" />



Aircraft ID:

value="$acid" />



Number Landings:

value="$nlandings" />



Number Hours:

value="$nhours" />






HTML;
} //end display function
?>






--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: works under mysql 5 but not under Oracle 11g1

am 24.11.2008 15:44:20 von Fred Silsbee

--- On Mon, 11/24/08, Chris wrote:

> From: Chris
> Subject: Re: [PHP-DB] works under mysql 5 but not under Oracle 11g1
> To: fredsilsbee@yahoo.com
> 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/


That code showed all...THANKS!

The data is being extracted but not making it to the variables.

while ($newArray = oci_fetch_assoc($result)) {
print_r($newArray); // everything!!! is there
foreach ($fields as $field){
${$field} = $newArray[$field]; // here...works under MySQL
}








--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: works under mysql 5 but not under Oracle 11g1

am 24.11.2008 22:52:03 von Fred Silsbee

--- On Mon, 11/24/08, Fred Silsbee wrote:

> From: Fred Silsbee
> Subject: Re: [PHP-DB] works under mysql 5 but not under Oracle 11g1
> To: "Chris"
> Cc: php-db@lists.php.net
> Date: Monday, November 24, 2008, 2:44 PM
> --- On Mon, 11/24/08, Chris wrote:
>
> > From: Chris
> > Subject: Re: [PHP-DB] works under mysql 5 but not
> under Oracle 11g1
> > To: fredsilsbee@yahoo.com
> > 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/
>
>
> That code showed all...THANKS!
>
> The data is being extracted but not making it to the
> variables.
>
> while ($newArray = oci_fetch_assoc($result)) {
> print_r($newArray); //
> everything!!! is there
> foreach ($fields as $field){
> ${$field} = $newArray[$field]; //
> here...works under MySQL
> }


fixed the problem but am not fully sure of the optimum code one should use!

I like the association idea but must change the $fields array

There is a better way than using count!

67 //get log_book_id table information
68 $user = "select * from log_book_id";
69 $result = oci_parse($conn, $user);
70 $r = oci_execute($result);
71
72 //display log_book_id information
73
74 while ($newArray = oci_fetch_row($result)) {
75 // print_r($newArray);
76 $count = 1;
77 foreach ($fields as $field){
78 ${$field} = $newArray[$count];
79 $count = $count +1;
80 // print_r(${$field});
81 // print_r($newArray[$field]);
82 }
83 $rowID = $newArray[0];
84
85 //note that we do not rely on the checkbox value as not all browsers submit it
86 //instead we rely on the name of the checkbox.
87 echo << 88
89
90 Check to delete record
91
92 $rowID
93 $fdate
94 $actype
95 $acid
96 $nlandings
97 $nhours
98






--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: works under mysql 5 but not under Oracle 11g1

am 24.11.2008 23:00:40 von dmagick

> fixed the problem but am not fully sure of the optimum code one should use!
>
> I like the association idea but must change the $fields array
>
> There is a better way than using count!
>
> 67 //get log_book_id table information
> 68 $user = "select * from log_book_id";
> 69 $result = oci_parse($conn, $user);
> 70 $r = oci_execute($result);
> 71
> 72 //display log_book_id information
> 73
> 74 while ($newArray = oci_fetch_row($result)) {
> 75 // print_r($newArray);

What does line 75 show and what do you expect it to show?


> 85 //note that we do not rely on the checkbox value as not all browsers submit it
> 86 //instead we rely on the name of the checkbox.

Well, that's wrong. The value is submitted IF the checkbox is ticked. If
it is not ticked, it is not submitted (this is the same in any language,
it's not a php specific thing).

--
Postgresql & php tutorials
http://www.designmagick.com/


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: works under mysql 5 but not under Oracle 11g1

am 24.11.2008 23:31:11 von Fred Silsbee

--- On Mon, 11/24/08, Chris wrote:

> From: Chris
> Subject: Re: [PHP-DB] works under mysql 5 but not under Oracle 11g1
> To: fredsilsbee@yahoo.com
> Cc: php-db@lists.php.net
> Date: Monday, November 24, 2008, 10:00 PM
> > fixed the problem but am not fully sure of the optimum
> code one should use!
> >
> > I like the association idea but must change the
> $fields array
> >
> > There is a better way than using count!
> >
> > 67 //get log_book_id table information
> > 68 $user = "select * from
> log_book_id";
> > 69 $result = oci_parse($conn, $user);
> > 70 $r = oci_execute($result);
> > 71
> > 72 //display log_book_id information
> > 73
> > 74 while ($newArray = oci_fetch_row($result))
> {
> > 75 // print_r($newArray);
>
> What does line 75 show and what do you expect it to show?
>
>
> > 85 //note that we do not rely on the
> checkbox value as not all browsers submit it
> > 86 //instead we rely on the name of the
> checkbox.
>
> Well, that's wrong. The value is submitted IF the
> checkbox is ticked. If it is not ticked, it is not submitted
> (this is the same in any language, it's not a php
> specific thing).
>
> -- Postgresql & php tutorials
> http://www.designmagick.com/

Array ( [LOG_ID] => 405 [FDATE] => 15-JUL-01 [ACTYPE] => C172 [ACID] => N17SJ [NLANDINGS] => 1 [NHOURS] => 1.2 )

thanks for the print_r tip!

I need to fix

${$field} = $newArray[$field]; ?? i need to properly use the association

I have seen no mention of the syntax ${$field} even though it looks reasonable!

I have two 900 pages books on "MySQL and PHP 5" one is 2 years old and the other is 2 years old

The check mark doesn't come into play until delete rows is selected.





--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: works under mysql 5 but not under Oracle 11g1

am 24.11.2008 23:56:01 von Fred Silsbee

--- On Mon, 11/24/08, Fred Silsbee wrote:

> From: Fred Silsbee
> Subject: Re: [PHP-DB] works under mysql 5 but not under Oracle 11g1
> To: "Chris"
> Cc: php-db@lists.php.net
> Date: Monday, November 24, 2008, 10:31 PM
> --- On Mon, 11/24/08, Chris wrote:
>
> > From: Chris
> > Subject: Re: [PHP-DB] works under mysql 5 but not
> under Oracle 11g1
> > To: fredsilsbee@yahoo.com
> > Cc: php-db@lists.php.net
> > Date: Monday, November 24, 2008, 10:00 PM
> > > fixed the problem but am not fully sure of the
> optimum
> > code one should use!
> > >
> > > I like the association idea but must change the
> > $fields array
> > >
> > > There is a better way than using count!
> > >
> > > 67 //get log_book_id table information
> > > 68 $user = "select * from
> > log_book_id";
> > > 69 $result = oci_parse($conn, $user);
> > > 70 $r = oci_execute($result);
> > > 71
> > > 72 //display log_book_id information
> > > 73
> > > 74 while ($newArray =
> oci_fetch_row($result))
> > {
> > > 75 // print_r($newArray);
> >
> > What does line 75 show and what do you expect it to
> show?
> >
> >
> > > 85 //note that we do not rely on the
> > checkbox value as not all browsers submit it
> > > 86 //instead we rely on the name of
> the
> > checkbox.
> >
> > Well, that's wrong. The value is submitted IF the
> > checkbox is ticked. If it is not ticked, it is not
> submitted
> > (this is the same in any language, it's not a php
> > specific thing).
> >
> > -- Postgresql & php tutorials
> > http://www.designmagick.com/
>
> Array ( [LOG_ID] => 405 [FDATE] => 15-JUL-01 [ACTYPE]
> => C172 [ACID] => N17SJ [NLANDINGS] => 1 [NHOURS]
> => 1.2 )
>

You will not beleiev this!

That great print_rt tip you gave me showed upper case keys in the association.....so

74 $count = 0;
75 while ($newArray = oci_fetch_assoc($result)) {
76 if ($count == 0) print_r($newArray);
77 $count = 1;
78 foreach ($fields as $field){
79 $fieldx = strtoupper($field); fixed <<<<<<<<<<<<<
80 ${$field} = $newArray[$fieldx];
81 $count = $count +1;
82 // print($field);
83 // print_r($newArray[$field]);
84 }
Not using count!





--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: works under mysql 5 but not under Oracle 11g1

am 24.11.2008 23:56:17 von dmagick

> Array ( [LOG_ID] => 405 [FDATE] => 15-JUL-01 [ACTYPE] => C172 [ACID] => N17SJ [NLANDINGS] => 1 [NHOURS] => 1.2 )

So everything is uppercase where you're expecting lower case.

while ($newArray = oci_fetch_assoc($result))
{
foreach ($fields as $field){
$field = strtoupper($field);
echo $newArray[$field] . "\n";

not an ideal solution but it'll work.


> thanks for the print_r tip!
>
> I need to fix
>
> ${$field} = $newArray[$field]; ?? i need to properly use the association
>
> I have seen no mention of the syntax ${$field} even though it looks reasonable!

Variable variables
(http://www.php.net/manual/en/language.variables.variable.ph p).

--
Postgresql & php tutorials
http://www.designmagick.com/


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php