Relational Databases and SQL in php

A Relational Database Management System (RDBMS) is a server that manages data for you. The data is structured into tables, where each table has a number of columns, each of which has a name and a type.

For example, to keep track of science fiction books, we might have a “books” table that records the title (a string), year of release (a number), and the author

Tables are grouped together into databases, so a science fiction book database might have tables for time periods, authors, and villains. An RDBMS usually has its own user system, which controls access rights for databases (e.g., “user Fred can update database authors”)

PHP communicates with relational databases such as MySQL and Oracle using the Structured Query Language (SQL). You can use SQL to create, modify, and query relational databases

The syntax for SQL is divided into two parts. The first, Data Manipulation Language or DML, is used to retrieve and modify data in an existing database. DML is remarkably compact, consisting of only four actions or verbs: SELECT, INSERT, UPDATE, and DELETE. The set of SQL commands used to create and modify the database structures that hold the data is known as Data Definition Language, or DDL. The syntax for DDL is not as standardized as that for DML, but as PHP just sends any SQL commands you give it to the database, you can use any SQL commands your database supports

Assuming you have a table called books, this SQL statement would insert a new row:

INSERT INTO books VALUES (null, 4, ‘I, Robot’, ‘0-553-29438-5’, 1950, 1);

This SQL statement inserts a new row but specifies the columns for which there are values:

INSERT INTO books (authorid, title, ISBN, pub_year, available)
VALUES (4, ‘I, Robot’, ‘0-553-29438-5’, 1950, 1);

To delete all books that were published in 1979 (if any), we could use this SQL statement:

DELETE FROM books WHERE pub_year = 1979;

Leave a Comment