日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

mysql like ilike_MySQLilike 子句

發布時間:2025/3/19 数据库 45 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql like ilike_MySQLilike 子句 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我們已經看到SQLSELECT命令從MySQLi表中獲取數據。我們也可以使用一個名為WHERE子句的條件語句來選擇所需的記錄。

等號(=)的WHERE子句可以正常工作,我們要做完全匹配。喜歡“name ="sai"”。但是可能有一個要求,我們要過濾掉所有結果,其中name應該包含“johar”。這可以使用SQLLIKE子句以及WHERE子句來處理。

If SQL LIKE clause is used along with % characters, then it will work like a meta character (*) in UNIX while listing out all the files or directories at command prompt.

Without a % character, LIKE clause is very similar to equals sign along with WHERE clause.

Syntax

Here is generic SQL syntax of SELECT command along with LIKE clause to fetch data from MySQLi table ?

SELECT field1, field2,...fieldN table_name1, table_name2...

WHERE field1 LIKE condition1 [AND [OR]] filed2 = "somevalue"

You can specify any condition using WHERE clause.

You can use LIKE clause along with WHERE clause.

You can use LIKE clause in place of equals sign.

When LIKE is used along with % sign then it will work like a meta character search.

You can specify more than one conditions using AND or OR operators.

A WHERE...LIKE clause can be used along with DELETE or UPDATE SQL command also to specify a condition.

Using LIKE clause at Command Prompt

這將使用SQL SELECT命令與WHERE ... LIKE子句從MySQLi表tutorials_inf中獲取所選數據。

以下示例將返回tutorials_inf表中的所有記錄,作者姓名以johar結尾,

root@host# mysql -u root -p password;

Enter password:*******

mysql> use TUTORIALS;

Database changed

mysql> SELECT * from tutorials_inf

-> WHERE name LIKE "%johar";

+----+-------+

| id | name |

+----+-------+

| 2 | johar |

+----+-------+

1 row in set (0.00 sec)

mysql>

在PHP腳本中使用LIKE子句

您可以將類似于WHERE ... LIKE子句的語法用于PHP函數mysqli_query()。此函數用于執行SQL命令,而后續的另一個PHP函數如果使用WHERE ... LIKE子句以及SELECT命令,則可以使用mysqli_fetch_array()來獲取所有選定的數據。

但是如果WHERE ... LIKE子句與DELETE或UPDATE命令一起使用,則不需要進一步調用PHP函數。

試試下面的例子返回所有記錄tutorials_inf對于其名稱中包含表喬哈爾-

$dbhost="localhost:3306";$dbuser="root";$dbpass="";$dbname="TUTORIALS";$conn=mysqli_connect($dbhost,$dbuser,$dbpass,$dbname);if(!$conn){die("Could not connect: ".mysqli_error());}echo"Connected successfully
";$sql="SELECT * FROM tutorials_inf WHERE name LIKE "%johar%"";$result=mysqli_query($conn,$sql);$row=mysqli_fetch_array($result,MYSQLI_ASSOC);printf("%s

",$row["name"]);mysqli_free_result($result);mysqli_close($conn);?>

樣本輸出應該是這樣的 -

Connected successfully

johar

總結

以上是生活随笔為你收集整理的mysql like ilike_MySQLilike 子句的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。