Learning PHP & MySQL Step-by-Step Guide to Creating Database-Driven Web Sites
Progress by pages
Notes
To get into mysql, you need to know info about the database server. In the command line, type mysql to access the command, but this doesn't seem to work for me, so I do "/Applications/MAMP/Library/bin/mysql" with -u root -p" to enter the mysql monitor.
arr = compact() is the opposite of extract, taking comma-separate strings (representing variables, but without the $), and placing them into an array. Reset is cool, it puts the pointer back at the beginning of the arr, useful in loops. Array_push(arr,elem) is the standard push, and pop, unshift, shift work as usual. Shuffle, and Merge are normal, and Keys and Values return only these into a numeric array.
Nested arrays work like elsewhere, just use [][] to get further it. Showing the insides of a nested array looks weirder, it has list($key,$val) = each $obj inside a while look. Must look into this. var_dump just deposits a whole array on the page, good for debugging. extract($var) is supercool, it brings all the keys out and sets them as variables. expand($array,EXTR_PREFIX_ALL,"prefix") will put a certain prefix before all the extracted vars.
To iterate through associative arrays, foreach($arr as $i => $v). Use count($arr) to return a length. sort($arr) reassigns everything to numeric indexes and orders them nicely. For associative arrays, try asort(); Sort has helpful extra parameters like sort_numeric, which will sort numbers correctly regardless of their digits.
You can assign things to empty slots in arrays with $arr[] = 'str', which just puts them in the first empty space (or, just put a value in []). A full array constructor looks like $arr = array(value,value). If you want to make an associative arraw, use ('ind' => 'val'). Test for arrays with is_array($arr).
&$varname allows you to point to the space data is being stored at for a Variable, so you can mess with it. It looks like arrays work like arrays and hashes both do in Ruby.
On page 104, the book claims that calling static methods on an object will product no results, but in my test, it worked just fine...might be a PHP version difference.
When you're inside a subclass, you can declare methods from a parent class, or reference them with parent::methodname, or do both. It's important to note that only the SUBCLASS'S constructor is called when creating a new object, so make sure that the subclass properly calls parent::__construct()
Inside a class, use $this->varname to ref. an internal variable. Something like 'class DomesticShorthair extends Cat {' will create a new subclass of Cat{}. You can now make DomesticShorthairs with their own unique properties, but which also have the properties of a cat.
When declaring scoped vars, you can say "private var" to make sure the var is only used by internal class methods. Scoped vars are public by default.
Description edit
PHP and MySQL are quickly becoming the de facto standard for rapid development of dynamic, database-driven web sites. This book is perfect for newcomers to programming as well as hobbyists who are intimidated by harder-to-follow books. With concepts explained in plain English, the new edition starts with the basics of the PHP language, and explains how to work with MySQL, the popular open source database. You then learn how to put the two together to generate dynamic content. If you come from a web design or graphics design background and know your way around HTML, Learning PHP & MySQL is the book you've been looking for. The content includes: PHP basics such as strings and arrays, and pattern matching A detailed discussion of the variances in different PHP versions MySQL data fundamentals like tables and statements Information on SQL data access for language A new chapter on XHTML Error handling, security, HTTP authentication, and more Learning PHP & MySQL explains everything from fundamental concepts to the nuts and bolts of performing specific tasks. As part of O'Reilly's bestselling Learning series, the book is an easy-to-use resource designed specifically for beginners. It's a launching pad for future learning, providing you with a solid foundation for more advanced development.
Additional information
- Pages: 428
- ISBN: 0596514018
- EAN: 9780596514013
- Dewey: 005.133
- Binding: Paperback
- Publisher: O'Reilly Media, Inc.