I had the same issue a, a good sql statement, no errors, but no results using wpdb.
The fix for me was a matter of having the correct collation/character encoding (e.g. COLLATE 'utf8_general_ci') for my table.
I had a query that worked, the table was replaced with a dump from an other server (and older server) and my query stopped working. It returned NULL or 0 even thought running the query in the database returned the proper results.
I create the tables both ways (a couple times because I did not believe it), ran the same data insert script, and did not change my PHP/wpdb code.
When the table was created with this this, my query did NOT work.
CREATE TABLE IF NOT EXISTS `vf_user` (
`id` mediumint(9) NOT NULL AUTO_INCREMENT,
`email` varchar(50) NOT NULL,
`full_name` varchar(25) NOT NULL,
`password` varchar(25) NOT NULL,
`role` enum('user','tester','admin') NOT NULL DEFAULT 'user',
`phone` varchar(25) NOT NULL,
`last_modified` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
`user_activation_key` varchar(100) DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE,
UNIQUE KEY `email` (`email`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=325 DEFAULT CHARSET=utf8 COMMENT='users table';
When it was created with this, my query did return results
CREATE TABLE `vf_user` (
`id` MEDIUMINT(9) NOT NULL AUTO_INCREMENT,
`email` VARCHAR(50) NOT NULL COLLATE 'utf8_general_ci',
`full_name` VARCHAR(25) NOT NULL COLLATE 'utf8_general_ci',
`password` VARCHAR(25) NOT NULL COLLATE 'utf8_general_ci',
`role` ENUM('user','tester','admin') NOT NULL DEFAULT 'user' COLLATE 'utf8_general_ci',
`phone` VARCHAR(25) NOT NULL COLLATE 'utf8_general_ci',
`last_modified` TIMESTAMP NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
`user_activation_key` VARCHAR(100) NULL DEFAULT NULL COLLATE 'utf8_general_ci',
PRIMARY KEY (`id`) USING BTREE,
UNIQUE INDEX `email` (`email`) USING BTREE
)
COMMENT='users with access to the virtual festival'
COLLATE='utf8_general_ci'
ENGINE=InnoDB
AUTO_INCREMENT=325
;
$wpdb->show_errors( true )before the query and I got the error back. It seems that WP started encoding the'character inside queries suddenly and out of the blue... Might be the reason of your problems too. Might want to feed '%thing%' as a parameter toget_reults.$wpdb->postsinstead ofwp_postsinside the query. I guess that somehow, for no apparent reason, the DB tables on our server got renamed? WTF?!?!?!