-------------------
Data Overview

The world is made of objects and objects have properties.
The value of a property is called data.
The name of a property is called meta data.
The data and the meta data is called information.

Humans like to know and share information.
The information might be text to read.
The information might also be used to create visual objects.

For instance, we use a FORM to collect information.
We can also FORM a colored circle in a collage from information.

The internet provides a global way to share information.
In our Web terminology...
People are called users or clients.
The client can send information to a server.
The server script stores information in a database.
The client can request information from a server.
The server script access the database and returns information.

Information does not pass directly betwee the client and the database
but must go through a server script for processing and security.

ORGANIZATION
We organize or group as drawn in nested boxes.
Removing the top lines and leaving the corners gives us arrays.
Adding a lines between the tops of the boxes gives us hierarchy.
Each box is called a node in a hierarchy.
The content is what is under the node (inside the box).
The context is what is above the node (outside the box).
In coding, the box or node is called an object.
The curly brackets of an object literal represents the box in code.
An object is data that holds information - meta data and data as properties.
Delimiters separate the meta data and data (:) and the pairs (,)

Other terms for meta data: name, identifier, id, key, index
Other terms for data: object, argument, value
Other terms for pairs: variable, parameter, property, element
Other terms for delimiters: separator, punctuation, operator, split

-------------------
Data Specifics

Here is a list of definitions of common Web based data systems.
Specifically, we look at HTML - PHP - MySQLi.

Data - a value (such as a string or number)
Meta Data - information about the data (name or id)
Information - the meta data and the data

Client - the user's computer
Front-end - the client
Server - a computer with software, such as Apache, connected to the Internet
Back-end - the server
localhost - a reference to the server when on the server
Database - a structure to store data on the server
Table - a grid structure to store data in a database
Fields - the column names of a table
Records - a row of data in the table
Primary Key - a unique id for each record
Query - a question provided as a statement
SQL - Structure Query Language used to access data
MySQL - a version of SQL - older and can be hacked with MySQL injection
MySQL Injection - inserting commands into the data that hacks the database
MySQLi - a version of MySQL that provides binding to prevent injection hacking
PHPMyAdmin - a Web app to manage databases with MySQL
cPannel - a Server management system that comes with PHPMyAdmin

SQL commands used in query statements:
INPUT - a way command to add a row to a table
SELECT - a way to get data from a table
UPDATE - a way to change data in a table
DELETE - a way to remove data from a table
VALUES - inputs to store - use ? for binding client data
WHERE - a command to limit data - use ? for binding client data

mysqli() - a class for MySQL that protects from injection hacking
PDO - an alternate system to MySQLi for accessing data
-> - a PHP operator to connect an object with a property or method (the . in JS)

// MySQLi without binding
$result = $mysqli->query($query) - a method that runs the query and gets a result
$num = $result->num_rows - a property holding the number of rows of data
$row = $result->fetch_row(); - get an array of requested field values (no names)
$arr = $result->fetch_assoc(); - get an associative array of field names and values

// MySQLi with binding - use this to collect client data
$stmt = mysqli->stmt_init() - a method that returns a MySQLi statement object
MySQL Statement Methods used for binding:
$stmt->prepare($query) - set the statement query
$stmt->bind_param("si", $name, $count) - put client input into ? in statement
$stmt->execute() - running the query
$stmt->bind_result($field, $field2) - put field outputs in provided variables
$stmt->fetch() - get the next record / row of data
$stmt->close() - close the statement if another statement is coming

Query String - the part of a URL after a ? that use used to send data
CGI Format - format of data sent on query string - prop=val&prop2=val
GET - a method of sending data on the query string
POST - a method of sending data hidden from the query string
$_GET["prop"] - collect GET data stored by PHP in associative array
$_POST["prop"] - collect POST data stored by PHP in associative array
isset() - a PHP function to test if a property has been set

JSON - JavaScript Object Notation - holds an object as a string
AJAX - Asynchronous JavaScript and XML - sends and receives data without loading page
JSONp - a way to send GET information without loading the page

AJAX vs JSONp
AJAX sends POST and GET but HTML page must be on server
JSONp sends GET (2048 character limit) but HTML page can be local
which has the advantage of being able to test our files without uploading to server.


----------
PHP Specifics

PHP - a procedural-based server scripting language with OOP addition
Procedural language - uses functions rather than Object Oriented
example: array(), count(array) rather than new Array(), array.length
<?php ?> - the way to start and stop php
Embed - PHP can be embedded anywhere in HTML
echo - the way to output HTML with PHP
$variable - the way to store a variable
Templating - inserting a variable inside a string "hello $name"
Concatenation - join strings together with the dot . in PHP
function name() {} - a way to run a block of code with called via name()
Array - a list of items []
Associative Array - like a JS Object Literal [prop=>"val", prop2=>"val"]
for($i=0; $i<10; $i++) {} - loop with start, condition and step
foreach($array as $val) {} - loop through an array
foreach($array as $key=>$val) {} - loop through an associative array
while(condition){} - loop while a condition exists
Conditional - if () {} a way to test a boolean result
Ternary - a single line conditional - condition ? do if true : do if false
preg_match(/regular expression/, $string) - a way to validate data
preg_match(/A(.)C/, "ABC", $array) - a way to remember data $array[1] is B
preg_replace(/regular expression/, "replacement", $string) - a way to adjust data
preg_replace(/A(.)B/, "C$1D", "ABC") - a way to replace with remembered data CBA
Warning ** preg_replace does not change the original string
so must assign the results back to the variable if desired

Debugging on Server
1. Make sure PHP pages are on the server
2. Make sure you have updated any changes to the server
3. PHP must have ; at end of statement (in JS it still runs)
4. Don't forget that concatenation is . and not +
