Querying data

It took quite a lot of time, but we are finally in the most exciting—and useful—section related to databases: querying data. Querying data refers to asking MySQL to return rows from the specified table and optionally filtering these results by a set of rules. You can also choose to get specific fields instead of the whole row. In order to query data, we will use the SELECT command, as follows:

mysql> SELECT firstname, surname, type FROM customer;
+-----------+---------+---------+
| firstname | surname | type    |
+-----------+---------+---------+
| Han       | Solo    | premium |
| James     | Kirk    | basic   |
+-----------+---------+---------+
2 rows in set (0.00 sec)

One of the simplest ways to query data is to specify the fields of interest after ...

Get Learning PHP 7 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.