PHP Converting a Variant to a String

Posted on 2007-08-05
Last Modified: 2013-12-13
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)};
$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,

Question by:chrishughes
    LVL 17

    Expert Comment

    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.
    LVL 13

    Expert Comment

    try this:

    echo $rs->Fields("description_short")->value;

    Author Comment

    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.

    Author Comment

    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.

    LVL 1

    Accepted Solution

    Closed, 500 points refunded.
    Community Support Moderator

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
    Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now