[問題] 請問PHP MySQL要如何查詢反斜線(\)符號?
$search="\\";
$link=mysql_connect("localhost","xxx","ooo");
mysql_select_db("xxx",$link);
$str="select xxx from ooo where xxx like '%$search%'";
$list=mysql_query($str,$link);
while(list($xxx)=mysql_fetch_row($list)){
echo $xxx."<br>";
}
mysql_close($link);
...
像上面我要查詢欄位xxx中含有反斜線(\)的所有資料並全部提取出來,但是查詢出來的結
果卻是空無一物,但明明xxx欄位有含有反斜線(\)的資料,這是為什麼呢?
*從資料表ooo提取欄位xxx所有含「反斜線(\)」的資料,其中MySQL的帳號是xxx、密碼是
ooo、資料庫名稱是xxx
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 219.80.130.92
※ 文章網址: https://www.ptt.cc/bbs/PHP/M.1434165464.A.850.html
※ 編輯: banana2014 (219.80.130.92), 06/13/2015 11:18:08
→
06/13 12:39, , 1F
06/13 12:39, 1F
→
06/13 12:40, , 2F
06/13 12:40, 2F
→
06/13 12:41, , 3F
06/13 12:41, 3F
→
06/13 12:42, , 4F
06/13 12:42, 4F
→
06/13 12:52, , 5F
06/13 12:52, 5F
→
06/13 12:53, , 6F
06/13 12:53, 6F
→
06/13 12:54, , 7F
06/13 12:54, 7F
例如我的資料表有欄位(xxx),其資料如下:
+-------------------------------------------+
| xxx |
+===========================================+
| Happy % ^_^ |
| Hello! \Hello\ |
| /\?"' |
| ~!@#$%^&*()_+|}{":?><`1234567890-=\][';/.,|
| Oh! My God!!! |
+-------------------------------------------+
照理來講應該要列出「Hello! \Hello\」、「/\?"'」、「~!@#$%^&*()_+|}{":?><`1234567890-=\][';/.,」這三筆資料的,
但是它卻只列出「Happy % ^_^」和「~!@#$%^&*()_+|}{":?><`1234567890-=\][';/.,」這兩筆資料,
該列出的它沒列出(只有列出一筆),而不該列出的它卻列出了,這是為什麼呢?
※ 編輯: banana2014 (219.80.128.18), 06/13/2015 13:13:59
→
06/13 13:16, , 8F
06/13 13:16, 8F
→
06/13 13:17, , 9F
06/13 13:17, 9F
→
06/13 13:18, , 10F
06/13 13:18, 10F
→
06/13 13:20, , 11F
06/13 13:20, 11F
→
06/13 13:20, , 12F
06/13 13:20, 12F
→
06/13 13:25, , 13F
06/13 13:25, 13F
→
06/13 13:27, , 14F
06/13 13:27, 14F
推
06/13 14:40, , 15F
06/13 14:40, 15F
→
06/13 14:40, , 16F
06/13 14:40, 16F
→
06/13 14:46, , 17F
06/13 14:46, 17F
→
06/13 14:47, , 18F
06/13 14:47, 18F
→
06/13 14:48, , 19F
06/13 14:48, 19F
<?
$search="\\\\";
$link=mysql_connect("localhost","xxx","ooo");
mysql_select_db("xxx",$link);
mysql_query("SET NAMES UTF8");
$search=mysql_real_escape_string($search);
if($search){
$str="select xxx from ooo where xxx like '%$search%'";
$list=mysql_query($str,$link);
while(list($xxx)=mysql_fetch_row($list)){
echo $xxx."<br>";
}
}
mysql_close($link);
?>
像以上的結果會是什麼都沒有顯示,請問該怎麼解決呢?
※ 編輯: banana2014 (219.80.128.18), 06/13/2015 14:55:00
→
06/13 18:40, , 20F
06/13 18:40, 20F
→
06/13 18:42, , 21F
06/13 18:42, 21F
→
06/13 18:42, , 22F
06/13 18:42, 22F
→
06/14 04:47, , 23F
06/14 04:47, 23F
→
06/14 04:47, , 24F
06/14 04:47, 24F
→
06/14 04:48, , 25F
06/14 04:48, 25F
→
06/14 04:49, , 26F
06/14 04:49, 26F
→
06/14 04:53, , 27F
06/14 04:53, 27F
→
06/14 12:02, , 28F
06/14 12:02, 28F
→
06/14 12:04, , 29F
06/14 12:04, 29F
→
06/14 12:06, , 30F
06/14 12:06, 30F
→
06/14 12:07, , 31F
06/14 12:07, 31F
→
06/14 12:08, , 32F
06/14 12:08, 32F
→
06/14 12:09, , 33F
06/14 12:09, 33F
→
06/14 12:11, , 34F
06/14 12:11, 34F
→
06/14 12:13, , 35F
06/14 12:13, 35F
→
06/14 12:14, , 36F
06/14 12:14, 36F
→
06/14 12:14, , 37F
06/14 12:14, 37F
→
06/14 13:08, , 38F
06/14 13:08, 38F
→
06/14 15:23, , 39F
06/14 15:23, 39F
→
06/14 15:24, , 40F
06/14 15:24, 40F
PHP 近期熱門文章
PTT數位生活區 即時熱門文章