How to get Node IDs of nodes whose titles contain a certain string? I'm trying to get a list of nodes whose titles contain a given string, in this case the term name of a term attached to another node.  

Based on other answers I've found online, I've thought this could work:

$sql = 'SELECT title FROM {node} WHERE title LIKE :title';
$result = db_query($sql, array(':title' =&gt; '%' . db_like($term-&gt;name)));


That's giving me a response but it's all empty, which makes no sense. 

Here's what the response looks like:

DatabaseStatementBase Object
(
[dbh] =&gt; DatabaseConnection_mysql Object
    (
        [needsCleanup:protected] =&gt; 
        [target:protected] =&gt; default
        [key:protected] =&gt; default
        [logger:protected] =&gt; 
        [transactionLayers:protected] =&gt; Array
            (
            )

        [driverClasses:protected] =&gt; Array
            (
                [SelectQuery] =&gt; SelectQuery
                [MergeQuery] =&gt; MergeQuery
                [UpdateQuery] =&gt; UpdateQuery
                [DatabaseSchema] =&gt; DatabaseSchema_mysql
            )

        [statementClass:protected] =&gt; DatabaseStatementBase
        [transactionSupport:protected] =&gt; 1
        [transactionalDDLSupport:protected] =&gt; 
        [temporaryNameIndex:protected] =&gt; 0
        [connectionOptions:protected] =&gt; Array
            (
                STUFF
                    (
                        [default] =&gt; 
                    )

            )

        [schema:protected] =&gt; DatabaseSchema_mysql Object
            (
                [connection:protected] =&gt; DatabaseConnection_mysql Object 
*RECURSION*
                [placeholder:protected] =&gt; 0
                [defaultSchema:protected] =&gt; public
                [uniqueIdentifier:protected] =&gt; 5670ef6385b8e5.94304345
            )

        [prefixes:protected] =&gt; Array
            (
                [default] =&gt; 
            )

        [prefixSearch:protected] =&gt; Array
            (
                [0] =&gt; {
                [1] =&gt; }
            )

        [prefixReplace:protected] =&gt; Array
            (
                [0] =&gt; 
                [1] =&gt; 
            )

    )

[queryString] =&gt; SELECT * FROM node WHERE title LIKE :title  
) 


Do I need to do something like this using CONTAINS instead?

$sql = 'SELECT title FROM {node} WHERE CONTAINS(title, :title)';
$result = db_query($sql, array(':title' =&gt; '%' . db_like($term-&gt;name)));
You need iterate over the node collection, you can use this code to do so:

$sql = 'SELECT title FROM {node} WHERE title LIKE :title';
$result = db_query($sql, array(':title' =&gt; '%' . $term-&gt;name . '%'));

foreach($result as $node) {
    //dpm($node);
    //$node is your object
    echo $node-&gt;title . '&lt;br&gt;';
}


Edit: If you want only specifics content types use this:

$sql = "SELECT title FROM {node} WHERE title LIKE :title AND type = 'your_content_type'";