我如何通过PHP检查MySQL中没有空间的字符串


How can I check a string without space in MySQL through PHP

我在PHP中有这样的查询:

DELETE FROM table1 
where filename="'.$name.'" 
and id=(select id from table2 where cat="'.$category.'")

问题是字符串$name没有空格,而表1中的相对字段有空格。我怎么做这个控制?

我用MySQL replace()函数解决了这个问题。Trim()函数不起作用。

Use TRIM():

DELETE FROM table1 where TRIM(filename) = "'.$name.'" and id = (select id from table2 where cat="'.$category.'")'

MySQL TRIM: http://www.w3resource.com/mysql/string-functions/mysql-trim-function.php

可以使用trim函数对列值进行修剪。

DELETE FROM table1 where TRIM(filename) ="'.$name.'" and id=(select id from table2 where cat="'.$category.'")
http://www.w3resource.com/mysql/string-functions/mysql-trim-function.php