0

I'm running a query that looks like this:

 $results = $DB2->query("SELECT COUNT(*) FROM auth_user as count WHERE email='" . $DB2->escape_str($email) . "';");

It's returning an object that looks like this:

DB_Cache Object
(
[result] => Array
    (
        [0] => Array
            (
                [COUNT(*)] => 0
            )

    )

[row] => Array
    (
        [COUNT(*)] => 0 // I WANT YOU!
    )

[num_rows] => 1
[q_count] => 1
[fields] => Array
    (
    )

)

I am trying to access the [count] array value using this:

$results->row['count'];

It's not returning anything. Any ideas what I'm doing wrong?

1
  • There is no count array value, though there might be a COUNT(*) one. Commented Jun 17, 2010 at 18:16

2 Answers 2

3

Change your SQL statement from COUNT(*) to COUNT(*) AS count

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a ton! Totally missed that.
1

Try this:

$results->row["COUNT(*)"]

The value between [] indicates the key of the array. You have to use exactly that key in order to access the array's value.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.