Some Motor Vehicles
Why would you want to create a table that does nothing but list cars? No idea! But apparently that's what we're doing!
Creating a database full of information is pretty simple. The first step is creating the table of information with the CREATE TABLE
statement in SQL.
In the creation of a table, one must assign one of the fields as a PRIMARY KEY
, and give each field a data type. Data types include the CHARACTER
, which stores a string of a given length; CHARATER VARYING
, which stores a string of a variable length. The differences between these two are simple, the VARYING type would not take up the full memory space if it doesn't need the full memory space.
Other data types include the INTEGER
, an integer that takes up four bytes; SMALLINT
, an integer that takes up two bytes; DATE
, which is used to store a proper date; and finally, MONEY
which stores a value of currency (the precision of the MONEY type is determined by the PostgreSQL's regional settings, and may not be available in other implementations).
Finally, there's the NOT NULL
option, which sets in stone the fact that each record in the database has to contain data in this field. A NOT NULL field cannot be left blank.
Now, of course, you're done, assuming an empty table is valuable to you. If it isn't, you can add data to the database with the INSERT INTO
statement, which allows you to specify specific fields, and specific data to enter into those fields, in a brand new record.
Once that's done, you might want to edit one or two records. This can easily be done with the UPDATE
statement. This statement has two useful options. The WHERE
option finds and selects exactly which record you want to edit, and the SET
option actually makes the change.
Finally, there's the DELETE
statement, which does exactly what it says on the tin. It'll delete whatever is specified with a WHERE statement, and must be used carefully.
But most commonly, when integrating this stuff in PHP, the SELECT
statement is the most common. It allows one to retrieve the data stored in the database. One would SELECT whatever fields they want, FROM
whatever table they want, WHERE
a certain field equals a certain value, or a certain other field.
It's so simple isn't it!?
Warning: pg_connect(): Unable to connect to PostgreSQL server: connection to server at "sql306.byethost10.com" (192.168.0.196), port 3306 failed: Permission denied Is the server running on that host and accepting TCP/IP connections? in /var/www/delta/intn2201/includes/functions.php on line 8
Fatal error: Uncaught TypeError: pg_query(): Argument #1 ($connection) must be of type PgSql\Connection, false given in /var/www/delta/intn2201/lab7_auto_info.php:51 Stack trace: #0 /var/www/delta/intn2201/lab7_auto_info.php(51): pg_query() #1 {main} thrown in /var/www/delta/intn2201/lab7_auto_info.php on line 51