Loops 4. MySQL and data-rich websites 5. Security and Good Practice 6. Working with JSON, XML and APIs 7. Object-Oriented PHP Development 8. Conclusion
Query Language. • MySQL is an open-source implementation of SQL. • Allows us to build and execute queries on a database. • Useful for building data-rich and persistent applications.
may, or may not relate to one another in some way. • Table: A storage mechanism for holding structured data, containing fields that do relate to one another. • Field: A single piece of data relating to each record in a table. Can be used to store multiple data types. • Record: A single entry in a table, containing data stored in the record’s fields.
a database, and its respective tables is using a GUI or web interface, such as phpMyAdmin. • phpMyAdmin allows us to build and define our tables using an interface similar to Microsoft Access. • When we create a database, we must also create a user account with specific privileges on the database. • Once we have created a database, we then need to create table which exists within it and actually store our data.
scope. • Things functions CAN access: • Other functions • Function parameters • Variables defined as global • Things functions CANNOT access: • Variables defined outside of the function (unless we declare them as global).
number of fields, and MySQL will easily handle tables with > 10,000,000 records if the table is well designed. • When creating our tables, we need to think about redundant data and data duplication. • A well designed database will have minimal data duplication, because this causes more space and slower response times with queries.
patterns which we need to bear in mind. • One-to-One Relationship: One record in a single table relates to a single record in another table. • One-to-Many Relationship: One record in a single table can relate to multiple records in another table. • Many-to-Many Relationship: Multiple records in one table relate to multiple records in another table.
can use: • Numerical Types: tinyint - integer between -128 and 127 smallint - integer between -32,768 and 32,767 mediumint - integer between -8,388,608 and 8,388,607 int - integer -/+2.147E+9 bigint - integer -/+9.223E+18 float - number with <= 24 decimal places double - number with 25 - 53 decimal places decimal - same as float / double, but stored as a string! bit - binary integer
maximum char length of 255 varchar - string with maximum char length of 65,535 tinytext - string with 0-255 characters text - string with 0-65,535 characters mediumtext - string with 0-16,777,215 characters longtext - string with 0-4,294,967,295 characters
date in format YYYY-‐MM-‐DD time - time in format HH:MM:SS datetime - time and date in format YYYY-‐MM-‐DD HH:MM:SS timestamp - integer of seconds since Unix epoch year - 4-digit year in format YYYY
way to identify records in a table. • Foreign keys allow us to identify relating rows in different tables. • Primary keys must be unique. • Primary keys should generally be integers. • We can define Primary Keys as auto-incrementing fields which means we don’t need to specify them when inserting data.
Essentially, creates a lookup (or index) of the table • By default, Primary Keys are always indexes • We can add more indexes, and should add them to fields which we will search regularly.
the table • UPDATE Will update the specified fields with the given values in the table • INSERT Will add new records to the specified table • DELETE Will delete the matched records from the specified table.