dongxiejie9387 2015-05-12 09:39 采纳率: 100%
浏览 45
已采纳

PHP对MySQL案例敏感

I know this question has been asked before. But nothing seems to work for me.

So I have this code below. What I am trying to do is Search in a database for table product_description and get the column name (this part so far works).The column name's collation is utf8_general_ci

   $SearchWord1 = "Squirl";
   $ExistingWord1 = "Banana";
   $ReplacerWord1 = "Orange";

I have 3 products:

name: SQUIRL banana pie
name: Squirl BANANA pie
name: SQUIRL banana pie

I want to search for Squirl,the search should grab both Squirl and SQUIRL. The same goes for banana $ExistingWord1 which is Banana and should also search for BANANA

    $sql1 = "UPDATE product_description SET name = REPLACE(name, '$ExistingWord1', '$ReplacerWord1') WHERE name LIKE '%$SearchWord1%';";

if ($conn->query($sql1) === TRUE) {
    echo "<h1>Everything worked as planned</h1>";
} else {
    echo "Error updating record: " . $conn->error;
}

I read several posts on stackoverflow and nothing helped me thus far.

  • 写回答

4条回答 默认 最新

  • douhao3562 2015-05-12 09:45
    关注

    I don't know if it's me but I'm not sure to understand your question.

    If all you want is to be sure to find the items you want regardless of the case, then you can probably use MySQL functions named UPPER(...) and LOWER(...) that allow you to convert a string in uppercase or lowercase respectively

    For example :

    SELECT name FROM product_description WHERE LOWER(name) = 'squirl';
    

    Will match both Squirl, SQUIRL or squirl

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?