PHP query in a view will cause website error I'm using a global PHP query in a View to find out the count of membership users.
The first query, that extracts the total number of users from the database works fine, but when I use the WHERE clause in a query for a comparison with a string, I received a website error like in the image attached below.

This is the query:

&lt;?php
$count_users_premium = db_query('SELECT COUNT(license_id) FROM {commerce_license} WHERE state="active"')-&gt;fetchField();
print $count_users_premium;
?&gt;


So, if I want to use WHERE some_number=3, it will work, but comparison with a string didn't work. (Drupal 8 version)
You cannot directly insert values into queries in Drupal. They need to be escaped. You would want something like this:

$count_users_premium = db_query('SELECT COUNT(license_id) FROM {commerce_license} WHERE state=:active', [':active' =&gt; 'active'])-&gt;fetchField();