Review: Head First PHP & MySQL by Lynn Beighley

Head First PHP & MySQL by Lynn Beighley
My rating: 4 of 5 stars

At OptimWise, I build websites with WordPress, and currently focus on front-end development (HTML and CSS). I’ve tweaked PHP, but I want to get better at modifying WordPress themes and plugins, which requires working with PHP and MySQL. This book was very helpful, as it includes step-by-step examples of building simple web applications with PHP and MySQL, and covers database fundamentals. The book is visual and easy to understand, explaining concepts and providing practical application. Like other Head First books, it’s full of quirky pictures and cartoons.

PHP

Loops

  • while loop: repeat code while a condition is met.
  • for each loop: loop through an array one element at a time, without using a test condition.
  • for loop: loop based on a specific number of iterations, using a counter and test condition.

Strings

  • Use trim() and mysqli_real_escape_string() to prevent SQL injection.
  • explode() breaks a string apart into an array of substrings.
  • implode() builds a string out of an array of strings.
  • str_replace() replaces text in a string.
  • substr() extracts part of a string.
  • preg_match() checks if a string matches a regular expression.
  • preg_replace() replaces a substring based on a regular expression.
  • strip_tags() removes HTML tags from a string.

Miscellaneous PHP

  • Pay attention to operand order with && (and) and II (or), because those operators are short-circuited whenever possible; if the first operand can determine the expression’s outcome, the second operand is ignored.
  • Single-quoted strings aren’t processed by PHP; double-quoted strings are.
  • isset() checks if a variable exists.
  • empty() checks if a variable has contents.
  • Include files: require_once() results in an error if an include file is missing, and it prevents files from being included more than once. include doesn’t do these.
  • Put an @ in front of any PHP function to suppress error reporting.
  • Use the ternary operator to simplify if-else statements: text expression ? statement 1 : statement 2.
  • Use a switch statement with cases to execute different code depending on a value.
    rand() returns a random integer.
  • simplexml_load_file() loads an XML file from a URL and makes the data accessible through an object.
  • mysqli_error() outputs error messages.

MySQL

  • Use AS to establish an alias.
  • Use LIMIT to limit the number of rows returned by a query.
  • Use the principle of least privilege. Create users and set specific privileges and table access.

Filed Under: 
Tagged With: ,

Want tips to rocket-boost your website?

Simply sign up.
Ready to Blast Off?

Let's talk.

Contact OptimWise
crossmenuarrow-right