PHP

PHP deals with values and making decisions about which path through your code should be followed at any given time. PHP allows you to connect to and interact with the database.

object-oriented programming (OOP), is a style of coding that allows developers to group similar tasks into classes. In OOP if a piece of information changes in your program, then only one change is required to update the code. Classes form the structure of data and actions, and use that information to build objects.

a PHP class
//PHP OOP - first instantiate your classes
class simpleClass { 
  //class member variables are called properties
  //property declaration
  public $var = 'the cat in the hat';

  //method declaration
  public function getvar() {
    //within class methods properties may be accessed by using the object operator ->
    //$this refers to the current instance of the object that you are in 
    echo $this->var;
  }
}

//assign an object to simpleClass
$ref = new simpleClass;

//call methods on the object
$ref->getvar();

the cat in the hat

object operator ->

the use of the object operator (the arrow ->) is an OOP construct that accesses the contained properties and methods of a given object.

echo $obj->property1

$this is a special self-referencing variable which points to the current object.

$this->name = $new_name
greeting

greeting   see a personalized greeting that uses a simple PHP class.

city smog

city smog   database of the most polluted U.S. cities.

season

Spring day 116

my
MySQL

access MySQL with PHP's mysqli Extension.

API application programming interface

When developing PHP applications that need to communicate with databases the necessary APIs are usually exposed via PHP extensions.

PHP's mysqli Extension in an API option for connecting to a MySQL database server.

APIs can be procedural or object-oriented. With a procedural API you call functions to carry out tasks, with the object-oriented API you instantiate classes and then call methods on the resulting objects.

make a connection
$db_conx = mysqli_connect("localhost", "hope", "passingword", "hopeful");
//evaluate the connection
if (mysqli_connect_errno()) {
    echo mysqli_connect_error();
    exit();
  } else {
	  echo "db connection success";
         }

if($results->num_rows === 0) { 
  echo 'no results';
} else { 
//output results from db 

switch
//check $pg
if ($pg)
{
switch($pg) {
  case "one":
  echo "hi";
  break;  
  case "two":
  echo "heh";
  break;  

  default:
  echo "hello";
  }
}