0

I want to execute query in my yii2 application. I'm using PostgreSQl. There is a table called list inside the user schema. If I try to build any query it returns 1. My code is here:

$numUsers = Yii::$app->db->createCommand('
    SELECT COUNT(*) FROM "user"."list"
')->execute();

Please show me my mistake in the query above.

1
  • 1
    if this is postgresql why did you tag it as mysql? and what is the error? Commented Apr 27, 2016 at 6:11

1 Answer 1

1

This is not related to the DB type in Yii2 if you want the result of a single value you should use queryScalar() instead of execute()

$numUsers = Yii::$app->db->createCommand('
      SELECT COUNT(*) FROM "user"."list" ')->queryScalar();
Sign up to request clarification or add additional context in comments.

1 Comment

Great! Thanks buddy for your help :-)

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.