SQL Queries
SQL (Structured Query Language) is a powerful, robust, and sometimes complicated query language that lets you manipulate information in databases. Luckily, you can get by at first with only the most basic knowledge of the SQL language to use it effectively in PHP. Table 7.1 lists some of the most frequently used commands. In the usage examples, news is the name of the table, and news_id is the name of a column in the table.
In general, it's good SQL programming practice to capitalize the SQL language keywords, such as SELECT, WHERE, and UPDATE. This makes your SQL queries easier to read, and easier for other programmers to look at your code and understand what is going on.
TABLE 7.1 SQL Basics
Keyword |
Definition and Usage |
SELECT |
Used to select data from the database. The data that you select is put into a table. |
|
Usage |
|
SELECT * FROM news WHERE news_id > '1' |
INSERT |
Used to insert new information into the database. |
|
Usage |
|
INSERT INTO news VALUES(NULL,'1','10-22-2000','Chris') |
DELETE |
Used to delete a row of data from a database. |
|
Usage |
|
DELETE FROM news WHERE news_id = '5' |
UPDATE |
Used to modify data in the database. |
|
Usage |
|
UPDATE news SET urgent = 'YES' WHERE news_id = '5' |