Why this code doesn't work?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
LastWalrus
Forum Newbie
Posts: 2
Joined: Fri May 31, 2002 9:16 am
Contact:

Why this code doesn't work?

Post 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?
rats
Forum Newbie
Posts: 21
Joined: Fri May 31, 2002 5:55 am

Post 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.
LastWalrus
Forum Newbie
Posts: 2
Joined: Fri May 31, 2002 9:16 am
Contact:

Post 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.
Post Reply