开发者

Searching for ampersands in a MySQL text field

开发者 https://www.devze.com 2023-02-15 15:12 出处:网络
I have this query: SELECT \'events\' AS tbl,events.*, users.name, users.lastname, (SELECT COUNT(*) FROM events_participants WHERE

I have this query:

SELECT 'events' AS tbl,events.*, users.name, users.lastname,
       (SELECT COUNT(*) FROM events_participants WHERE 
        events_participants.eventid=events.id) AS participants 
       FROM 
       (events INNER JOIN users ON users.id=events.organizer) 
       WHERE events.isConfirmed<=1 
       AND events.category='art&culture' 
       AND events.city='Roma(Rm)'AND events.datetime &开发者_开发百科gt;= '2011/02/22 22:30' 
       AND events.datetime<='2011/06/22 23:00' ORDER BY events.datetime DESC

The ampersand: & in art&culture causes the query to not return rows.


If that's the full query, looks like there should be a space between '2011/06/22 23:00' and ORDER BY


Possible issues:

  • datetime is a reserved word. Try replacing events.datetime with events.`datetime` everywhere it appears.


In MySQL you can search for Ampersands in a text field like this:

mysql> create table yar (id INT, mytext TEXT);
Query OK, 0 rows affected (0.02 sec)

mysql> insert into yar values(1, 'art&culture');
Query OK, 1 row affected (0.00 sec)

mysql> select * from yar;
+------+-------------+
| id   | mytext      |
+------+-------------+
|    1 | art&culture |
+------+-------------+
1 row in set (0.00 sec)

mysql> select * from yar where mytext = 'art&culture';
+------+-------------+
| id   | mytext      |
+------+-------------+
|    1 | art&culture |
+------+-------------+
1 row in set (0.00 sec)
0

精彩评论

暂无评论...
验证码 换一张
取 消