Page 1 of 1

Why this code doesn't work?

Posted: Fri May 31, 2002 9:16 am
by LastWalrus
(for context purposes)
$Con = new COM("ADODB.Connection") or die ("Error");
$Con->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=DB.MDB");
$Qry = $Con->Execute($SQL); // Recordset


This code works

$F = $Qry->Fields(0);
$FieldValue = $F->value;


But I would rather write

$FieldValue=$Qry->Fields(0)->value;

for which PHP complains with the following message:

Parse error: parse error, unexpected T_OBJECT_OPERATOR in line...

Can you tell me why?

Posted: Sat Jun 01, 2002 4:46 am
by rats
$Qry is a instance of a class
$Fields is a function of the $Qry class
$F is the return value from the $Fields function
$F->value returns the value of $F and puts it in $Fieldvalue


$FieldValue=$Qry->Fields(0)->value;

This asks for the value of the fields function in the $Qry class..
Functions dont have values but they can return values.

This is my guess anyway.

Posted: Mon Jun 03, 2002 9:00 am
by LastWalrus
Thanks for your reply

Your guess seems logical to me.

I wouldn't expect "Fields" to be a method of the object Recordset. Ms doc says it is a "collection".

Thanks for your explanation.