php-mysqlHow to use the LIKE operator in PHP and MySQL?
The LIKE
operator is used in PHP and MySQL to match a pattern in a string. It is used in SELECT
, INSERT
, UPDATE
, and DELETE
statements.
Example code
SELECT * FROM table_name WHERE column_name LIKE '%pattern%';
Output example
+----+------------+
| id | column_name|
+----+------------+
| 1 | abc |
| 2 | abcd |
| 3 | abcde |
+----+------------+
Code explanation
SELECT
: used to select data from a database*
: used to select all columns from a tableFROM
: used to specify the table from which to select dataWHERE
: used to specify a conditionLIKE
: used to match a pattern in a string'%pattern%'
: used to specify the pattern to match
Helpful links
More of Php Mysql
- How to use utf8mb4_unicode_ci in MySQL with PHP?
- How to join tables with PHP and MySQL?
- How to get the version of MySQL using PHP?
- How to write an update query in MySQL using PHP?
- How to count the number of resulting rows in a MySQL database using PHP?
- How to use a MySQL union in PHP?
- How to set a timeout for MySQL query in PHP?
- How to create an SSL connection to MySQL using PHP?
- How to get the last insert ID in PHP MySQL?
- How to fetch data from MySQL in PHP?
See more codes...