Slashdot Log In
Beginning PHP and MySQL 5.0
Posted by
samzenpus
on Mon May 22, 2006 02:52 PM
from the getting-started dept.
from the getting-started dept.
Ravi Kumar writes "PHP and MySQL use is so prevalent that nowadays it is hard to miss seeing a website on the net which has been built using these technologies. The beauty of PHP is in its open nature and the rich set of libraries and modules which imparts a lot of power and flexibility to the programmer. Similarly MySQL is a free database which is ideal for use as a backend for any website. And not surprisingly there are a plethora of books in the market which explains these two topics. One such book is Beginning PHP and MySQL 5 from Novice to Professional authored by W.Jason Gilmore published by Apress." Read the rest of Ravi's review.
| Beginning PHP and MySQL 5.0 - From Novice to Professional | |
| author | W.Jason Gilmore |
| pages | 860 |
| publisher | Apress |
| rating | 9 |
| reviewer | Ravi Kumar |
| ISBN | 978-1-59059-552-7 |
| summary | The beauty of PHP is in its open nature and the rich set of libraries and modules which imparts a lot of power and flexibility to the programmer. Similarly MySQL is a free database which is ideal for use as a backend for any website. |
Spread over 860 pages and divided into a whooping 37 chapters, this book covers the PHP Language and MySQL database in detail. As the name indicates, the book endeavors to hand hold a newbie in the various aspects of PHP programming like the language constructs and progressively brings him to the level of a professional. The first 21 chapters of the book solely concentrates on PHP where the author explains with the aid of examples how to write good programs in PHP.
The author starts the narration by giving a brief history of PHP and then moves on to explain all the syntax constructs of this language in great detail. Arrays, functions and classes have each been provided separate chapters of their own. Usually I have found many books related to programming jumping straight into describing the language syntax and about writing code. But this book has a dedicated chapter each covering how to setup and configure PHP and MySQL on ones machine irrespective of the OS being used which breathes some fresh air to this subject. PHP language has a very good similarity with C/C++ at-least in the syntax. And in the sixth chapter, the author explains the Object Oriented Concepts like object cloning, inheritance and polymorphism of this language with clarity.
The maturity of any programming language is gauged by the type of traps that it has developed to check the errors and exceptions that might be generated dynamically when a program is run. PHP has a rich set of features for handling errors. Earlier versions of PHP already took care of notifying errors through configuration directives and support for logging. But one thing this robust language lacked was support for exception handling. And from PHP ver 5.0 onwards, this feature has also been included in it. The 8th chapter in this book titled Errors and Exception Handling explains all these important concepts in detail. The fact that the author has provided snippets of code to illustrate each concept that is explained goes a long way in understanding this topic.
Another of PHPs strengths is in its support of a rich set of regular expressions and string manipulation functions. Using regular expressions, one can match just about any string or a sub-set of it and even do manipulations to the matched string on the fly. The string matching functions form the backbone of many user input validations. In the 9th chapter titled "String and Regular Expressions", the author explains with the aid of code how to use the rich set of string manipulation functions available in PHP to get the desired results.
The 10th chapter is solely dedicated to working with files and operating systems where the author explains in his inimitable style different ways of reading from and writing to files. All the frequently used file manipulation functions are explained in this chapter with the aid of examples.
The first 12 chapters of the book solely concentrates on explaining the PHP language to the readers. In the next 4 chapters, the author moves into practical aspects like explaining how to mix PHP with HTML elements, user authentication , handling file uploads, sending and receiving email using PHP code and so on. I found the section where the author explains how to build specialized programs such as a port scanner, subnet converter and bandwidth tester all with the aid of PHP code really fascinating. The author introduces the reader to some of the MySQL concepts in this part of the book like connecting to a database and reading data from database but the more detailed aspects of database manipulation are left for later chapters which deals with MySQL in more depth.
The 21st chapter titled Secure PHP programming throws light on topics related to enhancing security while coding in PHP such as enabling safe mode for people who run PHP in a shared-server environment, PHP's encryption capabilities, securely configuring PHP via its configuration parameters and so on.
From the 22nd chapter onwards, the book takes an all together different turn and moves into explaining the database concepts which plays an important part in any dynamically generated website. More specifically, the succeeding chapters concentrate on explaining the configuration and use of MySQL 5.0 and how one can use PHP to interact with the MySQL database. The chapter titled Introducing PDO throws light on the abstraction layer used between PHP and MySQL. I especially liked the 26th chapter where the author lists the different MySQL clients which are available to the user like mysql, mysqladmin, mysqlshow and so on. In fact, each and every tool which comes bundled with the mysql server is explained thoroughly with the aid of examples. But that is not all, this chapter also explains how to configure a mysql database using third party clients like PHPMyAdmin, MySQL Query Browser, MySQL Administrator and Navicat. In the section on securing MySQL, the author goes into the finer nuances of the topic. For example, with the aid of commands, the author explains how to make sure that the user connects with the database over secure sockets layer (SSL) or ways of encrypting the MySQL database traffic which is an eye opener.
But I would say the 29th chapter titled PHP's MySQL Extension is the most important chapter in the entire book just because it is in this chapter that the author explains in detail the variety of ways in which one can connect to MySQL database and retrieve or manipulate the data using PHP code.
In the 30th chapter titled PHP's MySQLi Extension, one gets to know how to use the enhanced MySQLi extension to connect to the database. The MySQLi extension contains more enhancements over its predecessor in that it is object oriented, supports prepared statements, provides transactional support, has better debugging capabilities among other things. But the down side as the author puts it is that it requires PHP 5.0 for it to work.
The last six chapters deal with special features of MySQL and how one can write PHP code to use those features. The features like stored routines, MySQL triggers and Views have been provided with a dedicated chapter of their own. And yes, from MySQL ver 5.0, support for views have also been incorporated in the database. And the fact that this book covers these new topics in detail makes this a truly useful book not only for budding programmers but also for the gurus among us.
I really liked the layout of the book. Each section is accompanied by PHP code snippet which shows how it is done. Just because one gets two books at the price of one does not mean that the book is short on detail. In fact the opposite is true and the 860 pages contain all that is needed for coming upto date with the latest version of PHP and MySQL. Of course the inclusion of a couple of pages giving a complete project such as a shopping cart application at the end of the book would have imparted a nice touch especially since this book is targeted at beginners too. But that is a minor detail and I guess there are limits to which a books of even this size can cram information. All in all an informative book which gives good value for money.
The author of this book W.Jason Gilmore has developed countless PHP and MySQL applications over the past seven years, and has dozens of articles to his credit on this and other topics pertinent to Internet application development. He has had articles featured in, among others, Linux Magazine and Developer.com, and adopted for use within United Nations and Ford Foundation educational programs. Jason is the author of three books, including most recently the best-selling Beginning PHP and MySQL: From Novice to Professional, and, with coauthor Robert Treat, Beginning PHP and PostgreSQL 8: From Novice to Professional. These days Jason splits his time between running Apress's Open Source program, experimenting with spatially enabled Web applications, and starting more home remodeling projects than he could possibly complete.
Ravi Kumar is passionate about all things related to GPL and open source and likes to share his thoughts through his blog."
You can purchase Beginning PHP and MySQL 5.0 - From Novice to Professional from bn.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.
This discussion has been archived.
No new comments can be posted.
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
Misleading Title (Score:5, Insightful)
What the hell is the title? (Score:4, Informative)
(http://mhawk.home.gowebway.com/Lark.html | Last Journal: Wednesday January 28 2004, @02:04PM)
LAMP Rocks (Score:3, Interesting)
(http://www.celardore.net/)
You can do some incredible stuff with PHP/MySQL if you put your mind to it. One of my favorite projects (it wasn't the definitive or only one!) was a windows app that hooked keypresses. Every so often it would upload the number of keypresses to some PHP / MySQL code and update your user profile.
The application potential is impressive, and not fully exploited the way I look at it.
Re:LAMP Rocks (Score:5, Insightful)
However, although I'm the first to brag about the power, simplicity, and performance that PHP and Apache offer when used by the right programmer, I do make a living off of ASP.NET/SQL Server applications, so please consider the following in the ensuing flamewar:
1. PHP is an extremely flexible scripting lanuage, that really excells at what it does: powering the back-end of a web application and interfacing with databases and the file system. Trying to make PHP do other things is possible, but is almost always a nasty hack.
2. The
3. Say what you will about SQL Server, but if we could just replace the M in LAMP with PostreSQL, or, well, anything other than MySQL, I would be happy. SQL Server is not my favorite database, but it is very good. MySQL has its niche, but I expect a RDMS to have stored procedures and transactions as standard fare.
(yes, I know 5.0 has SPs, and InnoDB gives you transactions, but I said "standard fare")
4. This is the most important point of all: There are just as many cookie-cutter, craptastic, insecure, bug-ridden PHP apps out there as there are ASP.NET apps. On the other hand, if you are smart and creative, and truly use the tools provided by either platform, you can create fantastic applications with either one, just as easily.
Re:LAMP Rocks (Score:5, Insightful)
PHP is an extremely flexible scripting lanuage, that really excells at what it does: powering the back-end of a web application and interfacing with databases and the file system. Trying to make PHP do other things is possible, but is almost always a nasty hack.
Help me out here: you're saying that PHP is extremely flexible, as long as the programmer only tries to write one type of program with it? Hmmmm?
I think we both recognize the truth: compared to Python, Ruby, or Lisp, PHP is not very flexible at all. It's a poorly designed, inflexible language that happens to have gained momentum at a critical era in the history of the WWW.
I don't want another PHP book (Score:2, Interesting)
Whoa, look at the time. Next language/framework/ide please...
Re:I don't want another PHP book (Score:4, Informative)
(Last Journal: Friday March 31 2006, @11:17AM)
I believe there's also a MySQL Cookbook, but my database use isn't so advanced that I need specific help on that just yet.
I'm still learning proper programming technique, while trying to learn PHP and MySQL and the fine points of CSS AND crank out a new web site that won't require a massive rewrite in a year.
but but (Score:1)
(Last Journal: Thursday May 05 2005, @07:40AM)
Tries to do too much (Score:2)
A book like the one being reviewed tries to do too much. When you're starting out, you don't want a a lot of detailed library stuff getting in the way. Once you've got the basics done, you don't want a book that teaches it like a course, you want a reference.
From the review's summary... (Score:1, Redundant)
(http://www.diamondcellar.com/)
ROR (Score:2)
(Last Journal: Tuesday October 30, @04:48AM)
Damn kids these days.
How does this book compare to.. (Score:3, Interesting)
(http://symbii.com/)
Owner of previous edition (Score:4, Informative)
Prevalent != Best (Score:2)
(http://bolson.org/ | Last Journal: Friday May 20 2005, @03:44PM)
Examine the options in the tools available to you, pick what works for you.
I've tried MySQL and PHP and mod-perl and CGI and python, but my current favorites are PostgreSQL [postgresql.org] and Tomcat [apache.org] hosting Java Servlets. No books required, their included documentation is quite good.
persistent problem (Score:5, Interesting)
this is a persistent problem with all of these programming in ____________ books. They teach the language and sometimes get around to dealing with good programming. Learning PHP, or java, or python, or whatever is still not learning to program. Learning to program effectively should be the first priority. All the OOP features in PHP5 are of no use to someone without good knowledge of OOP. Likewise, I'd gather that most of the insecurities in PHP are the result of poor design. PHP is great for its templating features, the ability to separate content from design, and its speed of development. But, that still doesn't make it secure or effective. How many times does a programmer get in trouble becasue they don't escape double quotes in a TEXT field in mysql, or account for malformed URL's, html, bad javascript, etc.?
No matter how good these books are, and I'm sure they do a good job of presenting all of PHP's features and strenghts, they still usually lack teaching how to design a web site/application, how to effectively use passwords, secure data queries, efficient programming, etc. That might be an altogether different beast, but there's a world of difference between using PHP in a web site and writing a good web app. I'd wish that the books would focus more on good programming techniques. I don't imagine everyone will buy the book otherwise, and not everyone will benefit the same, but I've not found too many books that put "programming" ahead of "programming in".
Only one chapter (Score:2)
(http://www.macromobility.com/ | Last Journal: Saturday March 25 2006, @01:33AM)
WAMP kicks a considerable amount of ass (Score:4, Informative)
http://www.en.wampserver.com/ [wampserver.com]
Too noisy for me. (Score:1)
For me -- doing is better than reading (Score:3, Interesting)
(http://www.unanimocracy.com/about.html | Last Journal: Tuesday April 04 2006, @12:04PM)
I learned the most I possibly could by downloading Wordpress (blog software), PHPBB (bulletin board software) and setting them up. I downloaded modifications and looked over the code in person.
Over the past few months I've become really adept at writing my own PHP and MySQL-based software, to the point that I'm starting to design my own CMS interface. Not a single thing I've learned from a book has stuck, but everything I learn in chomping on code in Notepad or emacs seems to stick forever.
Anyone else have problems with books on coding?
Already found a good one... (Score:1)
(http://anomalyent.com/)
Seriously though, as a relative n00b in the PHP world, I like the visual quickstart guides by Peachpit Press for PHP and Advanced PHP, where there is a practical example of what you might need to use PHP for, in addiion to a disection of the code being used. Both of these books deal with MySQL as well.
While I wasn't exactly scripting my own Nuke system in ten minutes, after some casual reading I was developing some rather unique portal systems that no one else had made available.
power and flexibility, gee wiz (Score:2)
The same could be said for python or perl. I think PHP's main "beauty" feature is how easy it is to install, nothing more.
What can you do with PHP and MySQL ? (Score:3, Funny)
(http://www.webgeekworld.com/ | Last Journal: Thursday April 27 2006, @07:47AM)
The beauty of PHP (Score:1, Flamebait)
beauty? PHP? Have you every looked at it? closely? Do you know any other solution?
Just look at the naming of is_null, empty and isset
Don't know the coding (Score:1)
This. Book. Suxxors. (Score:1)
Plug for TinyButStrong (Score:2)
I've no connection with either of these two projects, just a very impressed user (and the TinyButStrong promotional video is a wee gem
"Libraries and modules" (Score:1)
Too much information (Score:2)
technologies.
If you are an experienced programmer and want to learn PHP I would recommend
reading O'Reilly's "PHP in Nutshell" book. You can read through the whole thing
in less than a day and pick up most of what you will need to know. Also you
cannot beat the online docs as a reference.
A sorry situation (Score:1, Informative)
The fact that PHP and MySQL are the most deployed tools for web development is a rather sorry situation, given the deep shortcomings of both tools.
See these articles about the many PHP warts:
Experiences of Using PHP in Large Websites [ukuug.org]
Why PHP sucks [blogspot.com]
The PHP Ghetto [ianbicking.org]
You will be happier with a more mature and complete dynamic language like Python, or even (gasp ;-) ) Ruby.
Similarly, see these other articles about the many MySQL warts:
MySQL Hate [pythonmac.org]
MySQL Gotchas [sql-info.de]
Compare the last one with the one for PostgreSQL:
PostgreSQL Gotchas [sql-info.de]
Finally, an in-depth comparison between MySQL and PostgreSQL on Slashdot itself:
Comparing MySQL and PostgreSQL 2 [slashdot.org]
Finally, recall that both MySQL's transactional backends are now controlled by Oracle:
Oracle Acquires Sleepycat [slashdot.org]
Avoid both PHP and MySQL as much as you can, I say. There's better stuff out there.
First sentence needs fixing (Score:1)
There, that's better.
Moo (Score:2)
(http://tkatch.com/ | Last Journal: Monday October 29, @02:09PM)
It doesn't look like a database, it doesn't smell like a database. It's doesn't even taste like a database. And only the really nascent to the db scene would say it looks like a database.
It happens to have an language interface that on some level partially coincicdes with what many people think SQL should be. But, that's where it starts, and that's where it ends.
I'm not saying MySQL is a bad product. It's a wonderful product for quick web development and easy access to data, but calling it a database is like Win9x user saying they had a BSoD.
I think I'd rather learn (Score:1)
(http://www.myspace.com/infomusic)
You don't really need to buy a book for this (Score:2)
<?php
$connection = mysql_connect($location,$user,$pass) or die("Couldn't connect to DB server.");
success_code = @mysql_select_db($db, $connection) or die("Couldn't select database.");
$sql = "SELECT * FROM $table";
$result_set = mysql_query( $sql );
while ($row = mysql_fetch_array( $result_set )) {
do_something_with( $row );
}
?>
The only even slightly tricky part is initially setting up permissions on MySQL and creating a database. The MySQL and PHP online manuals will show you that and everything else you need to know. Also, the package phpmyadmin automates a lot of MySQL administration tasks (from a Web-based client), so you don't initially have to learn a lot of command line stuff.
Ubuntu has all of this packaged and readily installable from Synaptic (as does Debian for that matter). Just click and install apache2, php5, php5-mysql, mysql-server, mysql-client and phpmyadmin and you should be ready to go.
Really though, after you get the basic concept, you should try Ruby on Rails.
Re:Sec-exps already know PHP is the beginner's cho (Score:1)
Re:Sec-exps already know PHP is the beginner's cho (Score:5, Interesting)
Not blame the language? Why not? PHP is the only language that I know of that has like 6 or 7 functions just to escape strings to be injected in SQL queries and that still manages to get it wrong.
I mean, first time you try to hit a DB, you've heard about SQL injection you want to escape your inputs, are you using addslashes? Nope, and you should stripslashes too, if magic_quotes are active, because even though they're built in they fucking fail. Oh, there's an sqlite_escape_string, but you're using mysql so you'd probably use this lil' mysql_escape_string... except that you were really supposed to use mysql_real_escape_string, cause it's the real one you know. And the best part of all that shit? there is not one of the unsafe function that's marked anything even remotely close to "deprecated" or "dangerous", they are unsafe and should never be used, that's old news, and you can still use them n/p
Hell, PHP is the only language that I know of that does not feature any kind of prepared statement in it's standard DB interface. It only got prepared statements with the mysqli_ crapfest and that frigging piece of donkey poo requires you to create a prepared statement explicitely and then bind every single argument one by one to your statement.
This thing is the most retarded standard DB interface that's ever been born in this world, and it's only taken like 4 years for the Zend retards to unleash this abortion on us! Developers rejoice, maybe in 4 more years we'll get a DB interface on par with Perl's DBI or Python's DBAPI2...
And THIS is but one of the dozens of inherently stupid and/or insecure "features" PHP got built-in such as the good ol' REGISTER_GLOBALS, the hidden errors and notices, the lack of anything even remotely close to Perl's "use strict", the completely random and inconsistent function names and function outputs, the three-fucking-thousand functions all dumped into the global namespace (perl has 206, Python has 76 and ruby probably has less than a dozen)...
I'm all for blaming the builder, as long as he's got usable tools. PHP is nothing that can be called "usable tool" with a straight face, the whole "language" is a gigantic hack built with feces and vomit, it IS to blame, and blame it I do.
Re:Any website? (Score:2)
If the developers at "all those banks and stock exchanges handling vast loads" are using PHP and MySQL with the help of this book to develop their applications, then I'm going to stuff my money under my mattress. Lighten up a little.
The problem is that too many beginners are shown easy software development languages and techniques as if those are all they will ever need. This happened with Visual Basic in the 90s, and it is happening with PHP, MySQL and now Ruby on Rails. These are all great tools for development, but I have had personal experience of the disasters that can result when such tools are used beyond their capabilities.
Re:Sec-exps already know PHP is the beginner's cho (Score:2, Insightful)
(http://www.kermodebear.org/)
Is it the fault of the language? I can point to a few things where I can say, Shame on You, PHP!, such as the entire magic quotes 'feature' (which, iirc, is turned off by default now). But, as usual, it is the user, not the tool, that is at fault. This makes the language look bad because vulnerabilities pop up in software packages written in the language.
It's easy to spread FUD when that happens, especially to management and other uneducated people.
Some people say that the language should prevent programmers from doing stupid things. I disagree; I think the language should allow you to do what you want within the confines of its purpose, and if you happen to be making mistakes (such as not escaping data that goes into your queries) then shame on you. I don't see people complaining about C because it lets you point into kernel space and write garbage. If that happens, C programmers will point and laugh and say, "Ha ha, you silly newbie programmer!" not "Ha ha, C is retarded!"
I don't see why PHP should be any different. Sure, there are things that could be improved, but overall, most of the vulnerabilities I see are not the fault of the language. It's just the web's version of the VisualBasic syndrome (OMG I CN PRINT TXT 2 SCREEN, I R GOOD PROGMMR!!!!11one!).
The more used a language is, the more software that exists, and the more bugs that will exist - especially if it's an 'easy' language to learn.
Stats, please (Score:2)
(http://www.page1book.com/ | Last Journal: Tuesday July 06 2004, @04:02PM)
Or are you just repeating something you've heard?
Postgres may have more features and better support of SQL standards like transactions, triggers, stored procedures, etc, but these are things that improve data integrity, not performance.
MySQL has always been oriented to performance rather than features and its use as a backend for web sites has always been a primary goal for its developers.
Re:Any website? (Score:2)
Re:Sec-exps already know PHP is the beginner's cho (Score:1)