Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Girl Develop It! PHP/MySQL Session 1

kperch
October 18, 2011

Girl Develop It! PHP/MySQL Session 1

Intro to PHP

kperch

October 18, 2011
Tweet

More Decks by kperch

Other Decks in Education

Transcript

  1. Introduce Yourselves! Name Occupation/Company What do you like to do

    other than code? What do you want to learn?
  2. Course Format Session 1: Introduction to PHP Session 2: Introduction

    to MySQL Session 3: Mixing PHP/MySQL Session 4: Real-World PHP/MySQL, and where to go form this course
  3. Class Format (Today) Introduction to PHP Course Website/Tools/Materials What is

    PHP? Basic Structures/Syntax PHP Web Forms Lab/Homework
  4. Variables Just like variables in math- they represent a range

    of values over time, and an unknown or designated value at any one time. In PHP, they start with a $ You do not have to give you variables a type in PHP $hello = “Hello!” basic types include integers, floats, booleans, and strings.
  5. Naming Your Variables You can start variable names in PHP

    with letters, numbers, or _. These are also valid characters in any part of the name General Tip: Use descriptive names over short names If your variable name has more than one word, use $camelCase or $the_underscore_technique.
  6. Operators Again, like in math, these manipulate values standards :

    + - * / modulus: % - returns the remainder of left argument divided by the right concatenation : . “adds” two strings See example1-1.php to see them in action
  7. Operators Cont. Compare: <= <, > >=, == unary operators

    pre/post, --, ++ see effects in example 1-1 +=, -=, *=, /= perform operation with value and right side of = ($x += 2, $x = $x + 2).
  8. Some PHP Code [from example1-2.php] ...<body> <h1>My website!</h1> <?php $a

    = 4; $b = 2; $c = “I have ”; $d = “ apples!”; echo $c . ($a + $b) . $d); ?> </body>...
  9. If statements In english: If I have more than six

    apples, I will give you two. Otherwise, you will give me one. [see example1-3.php] if ( $my_apples > 6 ){ $my_apples -= 2 $your_apples += 2 } else { $my_apples += 1; $your_apples -= 1; }
  10. For/While Loops For: takes a value (part 1) and iterates

    until that value meets a condition (part 2), doing something to that value each iteration (part 3). for( $i = 0; $i < 10; $i++){ ... } While: Iterates until a condition is met. while( $i < 10 ){ ... } See example1-4.php
  11. Functions functions take a block of code and execute it

    when called, optionally on arguments passed to it. They can also optionally return a value. See example1-5.php function addTwoValues($val1, $val2){ $result = $val1 + $val2; return $result; }
  12. Objects Objects are a complex data type, comprised of attributes

    and methods- attributes are either primitive data types or other objects, and methods are functions. Functions that act on that particular instance of the object are instance methods. Functions that act separate of the object are static methods. See example1-6.php
  13. Why we’re going into unit testing Unit testing is an

    important practice Headaches of finding a bug can be large and numerous without testing The best time to pick up the habit is when you are learning to code
  14. What is unit testing? Short answer: A unit test is

    a piece of code that runs your code and asserts facts about the answer. If the assertions are true, the test passes. If they are false, the test fails. We’re going to go through example1- tests.php for examples/explanation
  15. Today’s Lab: Let’s create an object Pick an object that

    interests you, and let’s write the code for it Try to pick something with both attributes and methods Use Source Control! Don’t forget to write unit tests for your methods There is an example in example1-Lab.php
  16. Wrap-Up/HW Learned a lot about PHP today Types, operators, comparators,

    functions, objects, and unit tests! Homework: Finish Lab 1, Look over the slides for session 2.