How do I query a MySQL view in Drupal 7?
I don't think it's possible to query views using the DBTNG query builder: if you try to use db_select() with a view, it raises a PDOException complaining that the table doesn't exist.

Instead, you'll want to use db_query(). Let's assume you created a view named test:

CREATE VIEW test AS SELECT * FROM variable;


To get the value of cron_key, you'd do:

$name = 'cron_key';
$result = db_query('SELECT * FROM test t WHERE t.name = :name', array(':name' =&gt; $name));
$value = $result-&gt;fetchColumn(1);


The comment by drclaw on the db_query() API entry gives a number of examples which should help you out with figuring out how to manipulate a SELECT query using db_query().