Where In or clause for when a variable might not exist If I were to run a normal mySQL query that selects all nodes I would do this:

set @type='node';
select * from actions where type = @type;


but what if lets say I set type to be something that doesn't exist for example

set @type='';
select * from actions where type = @type or 1=1;


This will then in return select everything regardless. 

How do I do the same with db_query?

I thought just doing 

db_query("select * from actions where type = :type or 1=1;", array(':type' =&gt; '')).fetchAll();


but that doesn't work. Any ideas? (notice that :type is equal to '' just like in the mySQL example)
What you need to do is take that logic out of the SQL query, and instead use the query builder so to create your query; then you can add the IN statement conditionally, e.g.

// Set up your query
$query = db_select('actions')-&gt;fields('actions');

// See if you have data
if (!empty($types)) {
  // IN is the default operator for arrays so there's no need to specify,
  // but for the sake of an example...
  $query-&gt;condition('type', $types, 'IN');
}

// Get the results
$results = $query-&gt;execute()-&gt;fetchAll();