Scott
Scott

Reputation: 5848

PostgreSQL query not working in Yii2

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.

Upvotes: 0

Views: 732

Answers (1)

ScaisEdge
ScaisEdge

Reputation: 133380

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();

Upvotes: 1

Related Questions