Tuesday, October 28, 2014
PHP and Databases Intro
Databases and PHP
==================
PHp is interpreter. Translates PHP code to machine code, the processor runs and it outputs text (we use echo statements to output html friendly text).
Programming languages require connectors to get to database. PHP usually comes with this. Just have to enable it.
mysqli - class for working with mysql databases from PHP
Database Management System - This is your database server (or service). Manages access to the databases in an efficient manner.
Databases - Usually a collection of files efficiently organized to retrieve and update data. Contain tables and security information (login info and who has access to what).
Tables - reside in a database. They store the data in the form of rows. Tables have columns which multiple properties.
Index - way to improve the speed of searching a database based on certain fields, like if we wanted to search a dentist's name.
Dentist table example
~~~~~~~~~~~~~~~~~~~~~
Dentist (id -primary key, name - unique, address, phone, email_address - unique )
Column properties:
auto increment
primary key
data type - integers, strings (varchar, char, usually have to specify number of characters), date, datetime, bit (1 or 0)
unique
1, john smith, 123 street, 123 456 7890
2, beth , 456 street, 123 456 7890
3, debbie, 789 street, 123 456 7890
3, james, 789 street, 123 456 7890 <-- illegal , can't happen because of primary key constraint
4, james, 123 street, 123 456 7890 <-- illegal, can't happen because of unique key constraint
Dentist (id -primary key, name , address, phone, email_address - unique )
Better to use email address as unique constraint.
Operations you usually do on a database:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
designing (create tables, columns, constraints, indexes etc)
assigning access
querying (reading) -- usually do this in php
updating -- usually do this in php
inserting (create) -- usually do this in php
deleting -- usually do this in php
CRUD (create, read, update, delete) operations
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment