Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4434
  • Last Modified:

PHP Converting a Variant to a String

I am writing a php application which uses a MS access database and runs on a windows server.

When I try the following fragment:

$conn = new COM("ADODB.Connection") or die("painfully");
$conn->Open("DRIVER={Microsoft Access Driver (*.mdb)};
                DBQ=C:\\Inetpub\\vhosts\\acech\\httpdocs\\gallery\\web_data.mdb");
$rs = $conn->Execute("SELECT * FROM pictures");
echo $rs->Fields("description_short");
      
I get the following error:

Catchable fatal error: Object of class variant could not be converted to string in C:\Inetpub\vhosts\acech\httpdocs\gallery\photo.php on line 28

The field is stored in the database as type 'text'. Can anyone please advise me on how to convert this varient into a text string?

Many thanks,

Chris
0
chrishughes
Asked:
chrishughes
1 Solution
 
jasonsbytesCommented:
Is this line 28:
echo $rs->Fields("description_short");

I think maybe this returns an array and not a single (scalar) string.  So the problem is simply that you are trying to reference an array as a scalar.
0
 
MasonWolfCommented:
try this:

echo $rs->Fields("description_short")->value;
0
 
chrishughesAuthor Commented:
echo $rs->Fields("description_short")->value;

I get nothing when I try this - if I echo a numerical value from the same record it displays it correctly, so I know I am refferencing a valid field.
0
 
chrishughesAuthor Commented:
This turns out to be a stupid question! - I was in fact trying to read a null value as my code was pointing at the wrong database. Therefore the null variable was being returned as a variaint.

Chris
0
 
Vee_ModCommented:
Closed, 500 points refunded.
Vee_Mod
Community Support Moderator
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now