Hi!

I've got a strange problem... for the same query phpMyAdmin returns 4 results and db_query() returns none. Here is the query:

select * from log where log_data <= '2010-12-04' and log_data >= '2010-04-04' and typ LIKE '%dodanieSprzetu%'

the funny thing is that for similar query both phpMyAdmin and db_query() return correct number of result:

select * from log where log_data <= '2010-12-04' and log_data >= '2010-03-04' and typ LIKE '%edycjaSprzetu%'

and now I have no clue what is wrong. Thx for any help or advice!

[Edit:] changed title from 'query problem' pbarnett

Comments

jaypan’s picture

db_query takes placeholders, which include %d. If you want to use the percent sign in your query, you need to escape it with another percent sign:

'%%dodanieSprzetu%%'

But really, you should be doing this:

$something = 'edycjaSprzetu';
db_query('select * from {log} where log_data <= "2010-12-04" and log_data >= "2010-03-04" and typ LIKE "%%%s%%"', $something);

Contact me to contract me for D7 -> D10/11 migrations.

SmokOO’s picture

big THX!

jason_gates’s picture

Hi,
Please follow the forum guidelines here http://drupal.org/forum-posting

#
13 If you solve your problem, please follow-up, explain, and prepend '[Solved]' to the subject. #

Please help other folks find an answer to your issue. How about renaming you subject to something like "Using "%" and "like" with db_query()" or "Using a percent sign with db_query". A subject line that will allow other folks to find the issue and answer, :) :) Thank you ahead of time :)

bora-89’s picture

Thanks a lot! You have saved me many hours.
I was a little confused by this occasion.