Web Database Applications with PHP & MySQL 275
Web Database Applications with PHP & MySQL | |
author | Hugh E. Williams and David Lane |
pages | 563 |
publisher | O'Reilly |
rating | 9 |
reviewer | Brian Donovan |
ISBN | 0596000413 |
summary | A comprehensive, tutorial-style roadmap for building data-driven web applications with PHP and MySQL. |
PHP's speed of execution, gentle learning curve, and ease of development have contributed to its popularity, especially when teamed with MySQL, as a tool for building dynamic sites. Williams and Lane have written a thorough step-by-step guide to building web database applications with PHP and MySQL.
The Meat of the Book
Part I (Chpts 1-3) of Web Database Applications with PHP & MySQL (Web DB Apps) introduces the "Hugh and Dave's Online Wines" case study that's used to highlight the points made throughout the text and treats readers to the fundamentals of PHP, MySQL, and SQL - appropriate since the book assumes only some prior programming experience (not necessarily in PHP) and a general familiarity with HTML.
Chapters 4-9 (Part II) deal with the aspects of web application logic common to practically all data-driven sites : querying and writing to databases, maintaining state, and security. Chapter 4, "Querying Web Databases", includes a good explanation (Ex. 4-1) of the mechanics of connecting to and querying a MySQL db via PHP - numbered blocks of the example script correspond to sections in the accompanying text detailing what's happening at each point in the process (connect, query, retrieve results, process results, and close connection- unless you're using persistent db connections).
Chapter 5, "User-Driven Querying", explains how to pass data to PHP scripts using HTTP GET and POST. Although readers are initially shown parameters and parameter values being passed directly (as they are when register_globals is turned on in php.ini), the authors later explain why the same param:value pairs should instead be accessed through the global associative arrays $HTTP_GET_VARS and $HTTP_POST_VARS (the book was completed before the switch to $_GET and $_POST respectively with PHP 4.2.0) for security reasons. What the authors refer to as "combined scripts" (where the same script performs different functions depending on which, if any, variables in the GET or POST arrays, have been set, for example) are introduced and the reader is walked through the oft-used "next and previous links for query results" scenario.
In Chapter 6, "Writing to Web Databases", in addition to inserts, updates, and deletes, the authors explain one solution to the reload problem - i.e. where reloading a results page after some operation that alters the contents of the database has been performed (or even accessing a bookmarked url if HTTP GET was used to initiate the action) can potentially result in the operation being silently repeated or, if HTTP POST was used, the user being confronted with a big ugly "would you like to repost the data?" dialog. Locking (mostly how to make the best use of table-level locking) is also discussed in all of its glory. Chapter 7 deals with the validation of user input. The authors recommend and give an example implementation of dual server and client side validation (with JavaScript). Chapter 8 covers sessions (with and without cookies).
The chapter on security (Chapter 9, "Authentication and Security") mostly concerns user authentication. HTTP Authentication, managed HTTP Authentication (using PHP to validate encoded credentials from the HTTP Authorized header field), and handling your own authentication are considered, along with the security concerns inherent in stateful web apps - i.e., third party sites maliciously tricking browsers into coughing up cookies with login or session information for your site, session hijacking by feeding random session ids to the scripts until one corresponds to an existing session, etc. SSL is explained briefly.
The third and final section of Web DB Apps (Chpts 10-13) consists of a detailed examination of the guts of the wine store case study. Readers who find the commingling of application logic and html in the snippets of the wine store application discussed in the book distasteful will be gratified to know that, since publication, the authors have released a modified version of the "Hugh and Dave's Online Wines" code that uses the Xtemplate class (http://sourceforge.net/projects/xtpl/) to separate code from markup. Both versions are available in their entirety for download from the book website.
The five appendices, in turn, cover the installation and configuration of PHP, MySQL, and Apache on a Linux system, the architecture and workings of the Internet and Web, designing relational databases using entity-relationship modeling, how to define your own session handler prototypes and store session data in a database instead of files (the default), and provide an annotated list of PHP and MySQL resources (books, web sites, etc.).
The Good and the Bad
While it's clear that Web Database Applications with PHP & MySQL was written with the goal in mind of providing novice coders with a solid foundation for continued growth (or filling the niche of "handy reference" on the shelf of intermediate/advanced developers), the book manages to be comprehensive without patronizing the reader. I admit that I wouldn't have felt cheated if the authors had skipped the obligatory coverage of the history of the Internet, TCP/IP, and HTTP (Appendix B) in favor of, for instance, a discussion of web caching with an eye towards building cache-friendly apps, an important subject that all too gets short shrift from authors of web dev books. Also, some readers may be disappointed to find that the chapter on security doesn't relate to battening down your site against script kiddies and exploits, but that's really the sort of information that you should be getting from sites like PHP Advisory and Securiteam anyway.
For seasoned developers, this could be the book that you wish you'd had when you started out building web database apps and data-driven sites. Keeping a copy around for reference, especially if you frequently jump back and forth between projects in different languages/environments, also might be helpful - for those occasions when you need of a quick refresher in PHP/MySQL dev. Moreover, if you find yourself in the position of having to mentor junior developers (or helping non-coder friends) tasked with building or maintaining PHP/MySQL-based sites or apps, then lending them your copy or recommending that they buy their own could save you quite a bit of time and frustration.
Table of Contents- Preface
- Part I
- Chapter 1. Database Applications and the Web
- Chapter 2. PHP
- Chapter 3. MySQL and SQL
- Part II
- Chapter 4. Querying Web Databases
- Chapter 5. User-Driven Querying
- Chapter 6. Writing to Web Databases
- Chapter 7. Validation on the Server and Client
- Chapter 8. Sessions
- Chapter 9. Authentication and Security
- Part III
- Chapter 10. Winestore Customer Management
- Chapter 11. The Winestore Shopping Cart
- Chapter 12. Ordering and Shipping at the Winestore
- Chapter 13. Related Topics
- Appendix A. Installation Guide
- Appendix B. Internet and Web Protocols
- Appendix C. Modeling and Designing Relational Databases
- Appendix D. Managing Sessions in the Database Tier
- Appendix E. Resources
- Index
You can purchase Web Database Applications with PHP & MySQL from bn.com. Slashdot welcomes readers' book reviews -- to submit yours, read the book review guidelines, then hit the submission page.
don't need a book (Score:2, Interesting)
Re:don't need a book (Score:2, Insightful)
Re:don't need a book (Score:2)
Thumbs up for the people working on the PHP docs. They have made my life so much easier. I don't see why anyone would ever need a book for PHP.
LAMP systems (Score:1)
Re:LAMP systems (Score:2, Interesting)
Re:So is LAPP (Linux, Apache, PHP, PostgreSQL)! (Score:2)
I've said it before (Score:5, Informative)
That's how I learned php 3 years ago, and well, I'm better with php than most.
Real Programmers Learn By Doing (Score:5, Insightful)
I've said it before and I'll say it again: the best way to learn a language is by using it. Sit down at a computer with the manuals and start slinging code. You can't really learn a language by reading a book or going to a class. Real programmers learn by doing.
If you want to supplement your programming with a book or tutorial, fine, but keep your fingers on the keyboard. If you want to run sample programs, fine, but experiment and play with them. Change them, tweak them, go off on your own tangents. Better yet: throw out the tutorial as soon as you can write "hello world" and try to write some program of your own design. Keep the language and library references handy, because you'll need to refer to them often, but let your imagination and curiousity be your guide. Explore. Play. Learn. Real programmers learn by doing.
What I tell you three times is true.
--Jim
Re:Real Programmers Learn By Doing (Score:5, Insightful)
This strategy works fine if you never want to be any better than a good programmer (at least in that particular language). Learning by doing is great for getting started but leaves you a far cry from being someone that I'd want to hire.
As someone who has been through close to a dozen different languages, I've come to realize that the syntax is one of the easier things to pick up when learning a new language. What you need guidance on is about best practices in your new language.
It's the old "when all you have is a hammer, everything looks like a nail" dilemma. Just because the using lists is a convenient data structure in, say, ColdFusion, doesn't mean it should be what you reach for first in "language X". This is especially true when maker bigger leaps from compiled to scripted languages (what? Verbose comments slows things down??) and procedural to object-oriented languages. Some of the (sorry, I gotta say it) paradigm shifts are key to writing optimized code in the new language. And you'll never grasp those through trial and error.
So while I'll agree on the point that you have to have some hands-on to master a language, I'll strenuously object to the idea that hands-on can replace a good book (or other training source).
Re:Real Programmers Learn By Doing (Score:3, Insightful)
I agree wholeheartedly that it is important to learn the best practices of any given language. Syntax is easy to learn, but knowing the syntax to a programming language doesn't make you a good programmer any more than being able to write and spell makes you Shakespeare.
That being said, the PHP manuals are an excellent piece of work. It is my opinion that they are largely responsible for the popularity of PHP. I have used web development systems that I feel are superior to PHP, but I have yet to see anything that is both as easy to use as PHP and as well documented. Between the PHP manual, the PHP mailing lists, and the vast wealth of freely available example PHP code, I just don't see the added value of a book. The manual is more than enough to teach you the syntax, the tutorial will get you started on the correct path, and lurking on the mailing list is as likely as anything to teach you to use PHP properly. If you really get stuck, chances are good that you can examine a working example from some other production quality product.
Re:Real Programmers Learn By Doing (Score:2)
Re:Real Programmers Learn By Doing (Score:2)
Re:Real Programmers Learn By Doing (Score:2)
Not sure which scripting language you're referring to here. Even Javascript is now compiled and cached by browsers, so the pre-compiled version is used upon reloads (you can test this by running a benchmark script - the first run will take fractionally longer than all subsequent runs). I'm guessing perl doesn't fair any worse for having comments here and there.
A few years ago you would have been right though...
Re:Real Programmers Learn By Doing (Score:2)
As someone who has been through close to a dozen different languages, I've come to realize that the syntax is one of the easier things to pick up when learning a new language. What you need guidance on is about best practices in your new language.
True.... but the nice thing about the PHP docs is that they have this stuff in it. The user comments in the documentation are frequently filled with snippets of code, and the docs themselves often have some. Best practices? There might be some out there I don't know about... but I like how user input and the maintainers seem to keep good practices a part of the PHP docs.
Re:Real Programmers Learn By Doing (Score:2)
Re:Real Programmers Learn By Doing (Score:2)
Stop telling people how to learn! Every head is different.
I use a variety of approaches to learn. Websites are great for reference, but harder on the eyes than dead, pressed trees, and less portable IMO.
It is sometimes hard to learn by doing alone because you may be doing something that works, but doing it the hard way without knowing that there is a better way.
One a side note, one thing that bothers me about PHP is the lack of regional variables (sometimes called "globals" in web languages) without funky qualifiers. If I want to reference something often, I don't want to have to keep qualifying it. Qualifying also causes Law-of-Demeter-like re-work, or declaration rework, if you factor a local var to be regional.
It is true that the PHP approach better "documents" a routine's interface to its surroundings, but sometimes a routine is dedicated to a particular task and I don't want to generitize it. Let it sit where it sits.
Re:I've said it before (Score:4, Insightful)
You need something that puts pieces together, puts things in perspective, gives you a 10,000 mile high view and drills down into certain aspects of what it's trying to cover.
Just being devil's advocate. I learn from source code. After that, I hit websites that dive deep into the subjects (like the main php site), and finally I'll take a college course (community college, mostly) on the subject just to get it on paper that I know it.
Amazing... (Score:3, Funny)
I really wish... (Score:2)
Another O'Reilly Book (Score:1, Funny)
"If it's an O'Reilly, it's got to be good."
Another great book on the topic (Score:2, Informative)
Agreed. Another one I used: (Score:3, Informative)
Welling and Thomson's book is a good reference for those who want to get to grips with practical projects straight off the bat. It includes webmail, shopping cart, session control, and web-forum/weblog applications as a matter of course, and begins with a sturdy look at PHP first, moving to MySQL once the basics are covered.
Greenspan and Bulger's text is perhaps more traditionally concerned with constructing databases and the programming that surrounds them. Both books cover the material equally well, though I found some nuisances in the first book.
Re:Another great book on the topic (Score:2)
PHP and MySQL Web Development
I've read this one too.... (Score:1, Interesting)
This book is a perfect example of why I choose O'Reilly whenever in doubt. Chapter 1 is an overview of how web applications are put together. Chapter 2 goes through all the basic PHP syntax (stuff that would take other books several fluffy dry chapters to process). Chapter 3 gets you through all the mySQL and sql basics so you feel comfortable with that, too.
There's no 4 page tutotial entitled: "Using a text editor: Wordpad" There's also no kitch "Employee Database" example cop-out. Instead, Hugh and Dave give a realistic and usable storefront application. This book alone is probably enough for the independent web developer to get a functional site up for her/himself or a client.
Re:COMMENT STOLEN FROM AMAZON DOT COM (Score:2)
Guilty until proven innocent?
Psuedonames are all over the web. You don't know that they are different persons (yet).
Well (Score:1)
Re:Well (Score:2)
It must a requisite (Score:1)
You all are all wet use sh for all your web CGI / programing / culinary needs. It parses, dices, and slices.
Web Application Database security links (Score:1, Informative)
www.owasp.org [owasp.org]
www.sqlsecurity.com [sqlsecurity.com]
Umm... why not just read the docs? (Score:5, Informative)
A useful little tidbit: If you want a quick way to look up information in the PHP Manual, go to http://www.php.net/whatever-you-re-looking-for. For example, http://www.php.net/mysql [php.net] will take you straight to the reference pages for MySQL.
Re:Umm... why not just read the docs? (Score:2)
But MySQL doesn't do UTF-8... (Score:4, Interesting)
aminamals (Score:5, Funny)
Book has a missleading title (Score:5, Informative)
If that's what you want then it's a good book. If you just want a general overview of the different sites you can design using the php/mysql combination then I think you'll be disappointed. I was.
Re:Book has a missleading title (Score:2)
Re:Book has a missleading title (Score:2, Informative)
Re:Book has a missleading title (Score:2, Insightful)
The techniques learned from making an e-commerce site can be applied to just about any database-based site.
Re: reminds me of "C Bible" = "build calculator" (Score:2)
Teaching with separate, well thought out examples (small or medium size each) is much better. The "grandmaster project" also needs to force usage of a lot of functionality that hurts the teaching and the intelect as well.
Transactions? (Score:4, Insightful)
Since transactions are a relatively new part of MySQL (and so, presumably new to PHP's interface to MySQL), a good part of the value of a new book on the subject of PHP/MySQL website building would relate to that new feature (which would also help with the double-entry problems mentioned in the review).
So, does the book cover this topic or not? I can't tell from this review.
I *hate* DB programming in PHP! (Score:3, Informative)
$row->firstname\n";}
$row->firstname\n";}
If you're starting with a new project and know for a fact, beyond the shadow of a doubt, that you'll never be changing database backends, then PHP isn't too bad. If there's an possibility (however remote) that you'll ever move from, say, MySQL to PostgreSQL, then DO YOUR WORK IN PERL! I can't tell you how much I missed Perl's DBI::DBD modules - I could've completed the transition in an hour or two instead of weeks. I know that there are efforts to provide similar functionality in PHP, but it just isn't to Perl's level yet.
Re:I *hate* DB programming in PHP! (Score:3, Interesting)
Actually, I just migrated a database-driven website from MySQL to Oracle without a hitch, all using php.
A database abstraction layer was used which made all the difference. I used dal [sourceforge.net], which is a nice object-oriented layer that only involves changing a single line of code to change different databases.
Personally, it sounds to me like your company's problem was bad design (not allowing for expansion) rather than php.
Re:I *hate* DB programming in PHP! (Score:4, Insightful)
Personally, it sounds to me like your company's problem was bad design (not allowing for expansion) rather than php.
Thank you! I am absolutely sick of developers blaming PHP for being bad at switching databases because they didn't built their app properly. PHP lets you get right down to the raw nitty gritty DB specific stuff -- which is nice, but you really shouldn't ever be using those UNLESS you are writing a wrapper, or really don't care about database independence. I really wish the php.net official manuals would warn new developers of this.
The very fact that this book targets PHP and MySQL sort of ticks me off too -- why not PHP and DB wrappers? Why MySQL of all things too? It's horrid (sorry)
Re:I *hate* DB programming in PHP! (Score:2)
All the Java apps I have tried run so slow I can't even use them. Great, It's well designed and I *could* run it anywhere, but would I *want* to?
I am talking about LimeWire, Phex, PanoTools and apps of that size (well, Panotools is great, as slow as irreplaceable).
Database abstraction classes are available (Score:3, Informative)
Yes, there are arguments to be made against DB abstraction layers if you're using very specific features on one platform that might not be available on another (e.g. Postgres' foreign keys and subselects vs. Mysql's lack of them (er, last time I used MySQL anyway))
But if you're doing fairly run of the mill SQL stuff, check out the PEAR DB class [php.net] or ADOdb [weblogs.com]. Either one implements a standard set of methods for interacting with databases regardless of the backend.
Re:I *hate* DB programming in PHP! (Score:2)
But I'm surprised you would think a DBI layer would absolve you from lots of work in changing DB backends?
Changing RDBMs' isn't something you do every day, nor should it be taken lightly. Expecting to not have to modify code (which is a reason I hear all the time for DB layers) is false for several reasons:
1) For all but the simplest SELECT statements most RDBMs' SQL implementation differs enough that you'd have to re-write your complex queries. As shown in your example of transactions, Oracle uses sequences to create auto_incrementing integers. MySQL uses a column type of 'auto_increment' and requires you to explicitly insert NULL. Sybase and MS SQL use IDENTITY columns but requires that you leave the identity column OUT OF the SQL statement.
2) You should check EVERY SINGLE QUERY to make sure it performs well in your new environment. Oracle may use an index (or two) in a situation when MySQL will table-scan, causing your query to take 200x as long to complete. Switching your backend DB should not be a 'fire and forget' situation!
3) Most Enterprise RDBMs' include the concept of Stored Procedures. These, actually, are a GREAT way to achieve DB independence (to some degree) in your application. For example, say you have some code like this: *_query( "get_user_info $userid" ); As long as my stored procedure is named the same, takes the same parameters, and behaves in the same manner I don't have to change that line at all! I can write the SQL in Oracle's PL/SQL, Sybase/MS SQL's T-SQL, etc. and the application logic does not have to change.
However, DB abstraction layers are nice since you can include error checking and array-fetching as you showed very easily. I'd say the greatest advantage to using an abstraction layer are the class functions you create for it. I use DB layers on all my programs for those reasons, NOT for DB independance.
Re:I *hate* DB programming in PHP! (Score:2, Interesting)
Me too. I uninstalled PHP a while back. The database-specific functions exemplify what is both good and bad about PHP.
BAD: Nothing is really object-oriented. Code is completely un-portable. PHP code is useless in other environments like binary or batch development (unlike Java, VB, C++, etc...and no whining about how someone's made a PHP->binary compiler...it ain't the same.)
GOOD: Nothing is really object oriented. Each of the modules (one hopes) is stripped down and about as fast as possible. In the case of database access, you're opening native connections directly the database instead of wading through ADO/ODBC/JDBC or any of the other things that abstracts your access. Another example, mailing functions...works DAMN well, and is as simple as can be (ASP, Java obviously can do it...but) from both a programming and functional standpoint.
So I suppose I'd use PHP if I had a moderately small site that I wanted to use for a fairly specific purpose, one that once I'd built I wouldn't have the time to port to something else anyway. However, if the site was something that would be maintained by a large number of people, over a long period of time, and have to integrate with a variety of databases and such, I sadly wouldn't consider PHP for a second.
Re:I *hate* DB programming in PHP! (Score:2)
The code is interpreted so how can it not be portable?
PHP code is useless in other environments like binary or batch development (unlike Java, VB, C++, etc...and no whining about how someone's made a PHP->binary compiler...it ain't the same.)
Again can you explain more clearly? I use PHP for batch processing without any problem. You can also use PHP to write command line or desktop apps, though it's obviously not suited to developing large desktop apps as it wasn't designed for that.
So I suppose I'd use PHP if I had a moderately small site that I wanted to use for a fairly specific purpose
This is what PHP is primarily designed for, imho. I think you needed to read the instructions on the side of the tin before purchasing...
Phillip.
Re:I *hate* DB programming in PHP! (Score:2)
Well this is mostly a lie. There is no database abstraction layer in PERL either DBI is a library. There is no database abstraction layer in VB or C++ either ODBC and ADO are libraries. Same with python.
So what you meant to say was that as far as PHP is concerned it's no different then VB, PERL, python, or C++ when it comes to database abstraction. You have to download and use some external library.
"Finally, yes, we agree about the smaller site use for PHP"
If you are hack then all you are going to do is small sites anyway (and bad ones at that). The fact remains that there are some HUGE sites that use php. You might want to look at sourceforge or insight.com as examples. PHP provides you with everything you need to build large complex web applicatons that are object oriented and easy to maintain. Maybe you ought to look into some of the more advanced aspects of it.
Re:I *hate* DB programming in PHP! (Score:2)
Apparently you are more dense then I thought. Ok let me try to explain it again. If you were using perl then you'd have to download a library called DBI. This library enables you to write database independent applications. If you were using Visual Basic, C, C++, python etc you'd have to do the exact same thing.
If you are using PHP and wanted to write database independent applications you'd have to do exact same thing. You'd download phplib, PEAR, ADODB, metabase or any database abstraction library and write your application. I am of course presuming that someone of your intelligence level can actually seek, find, download and install libraries for PHP. I am making this presumption because you are so far exhibiting profound ignorance of the existance of these types of libraries. I hope that this post can ease some of that ignorance. If you need the URLs of where you can download these libraries please ask and I will gladly help you out.
" I will look more at PHP, although if most developers are as ire-ridden as you I doubt I'll join that community."
I don't think anybody will cry if you decide to use something else. The PHP community is thriving despite your absence and will continue to do so with or without you. Nine million web sites have decided to use it and I don't think any of us will panic because mborland doesn't like us. In fact it might be better for us if people who are unable to do simple searches on google stay away.
However in the spirit of doing my part to ease your ignorance I would like to present you with this [google.com] link. Here you will find many database abstraction layers which you can download, install and use.
Re:I *hate* DB programming in PHP! (Score:2)
Were we to start now I would do things much differently, but I still contend that by the time you've started installing abstraction layers, etc., then you might as well use Perl from the beginning.
Re:I *hate* DB programming in PHP! (Score:2)
My first thought when I saw the Xtemplate class was "hmm...this looks a lot like what I used to do with perl and Sam Tregar's (excellent) HTML::Template module." I say "used to" because there were a couple of projects around here that had PHP/MySQL as a requirement, and by the time those were done we had a large reusable code-base....and here I am, slinging PHP instead of my beloved Perl.
There is one thing that makes PHP more attractive for me. We deploy sites on hosts all over the place - we never know what's going to be installed. When you're using Perl, you never know what you're going to be able to use - is DBI installed, AnyDBM, anything? With PHP, you know you've got a database, and there's a 99% chance it's MySQL.
One thing I'm really looking forward to with Perl 6 (to go on a tangent) is this promise of SDKs...if sysadmins can just grab the "Web Site Development SDK", I may yet get to return to it.
You don't need OO crap to wrap DB operations (Score:2)
Exactly!
You don't even need OO. Wrap it in functions. You can also consolidate many things so that if 90% of your code uses the same database or connection handle, you don't have to keep referencing it over and over. Open them all in a single function.
Use optional named parameters if you need to deviate from the norm (std. connection, etc.) on occasion. That way you don't clutter up 90 percent of the calls for the 10 percent that deviates. Optional named parameters are great for that kind of thing. (I haven't used named parameters yet in PHP, so I don't know if they have any limitations).
Don't fall for all that bullshOOt that only OOP can protect you from DB vendor changes. Those OO book authors simply don't know how to use procedural/relational programming correctly. They had a bad experience in C, and tossed out the baby for OO.
oop.ismad.com
Re:I *hate* DB programming in PHP! (Score:2)
Comparing PHP with Visual Basic might not be too far off. Basically the reason I started writing in PHP was that mod_perl was not available at the time and kicking off cgi scripts was becoming a royal pain in the butt.
PHP is a focused language though and doesn't have the full functionality of perl, but then again it is easier to pick up than perl. I'd agree.
As for MySQL comparied to access. They aren't compariable in the least... First and formost MySQL is a database something that I wouldn't even consider Access for. Access is slow clunky and doesn't or at least didn't support SQL standards. MySQL is one of the fastest databases available currently, for most sites it can do anything that they require.... The only thing Access has going for it is the user interface... The tools for developing new databases quickly for non-admins can be helpful at times..
Hmmm, sorry for the lack of details, but while I think your comparison of php and vb is reasonable, access just doesn't compare to mysql as a database.
Re:I *hate* DB programming in PHP! (Score:2)
There is a web-based interface to MySQL called PhpMyAdmin (do a web search). I think it is OSS. It is a little clunky, but it beats the MySQL command-line. (I don't have anything against command-lines in general, I just don't like doing DB management on one. Rows and columns are best managed using rows and columns.)
Re:I *hate* DB programming in PHP! (Score:2)
Actually I used to be a MCP in access 94-97, Most of my knowledge of access and the jet database comes from that time... Until Microsoft came out with MSSQL 7.0 they didn't have a proper database, and I doubt that they have put that technology into access...
Anyway, I don't work with Microsoft products much anymore, but I do miss the ease of access. But power, flexibility, security and costs are a bit more important.
Re:I *hate* DB programming in PHP! (Score:2)
You're preaching to the choir. My client is consolidating several web and database servers, and their webapps are variously running against InterBase, PostgreSQL, and MySQL.
Today I moved a whole site from MySQL to PostgreSQL by adding a ZPsycoDA adapter and pointing the ZSQL object at it. After 10 minutes of work, I'm done, and the site works flawlessly.
zope stats (Score:2)
'real OOP' - PHP is 'good enough' at OO for most projects (if 'good enough' is sufficient reason to use Zope, it's sufficient to argue for PHP too).
Zope *needs* to have better presentation - we've installed it a few times and it's always confusing as sin, with no good documentation.
Re:zope stats (Score:2)
I do agree about documentation, however. I'm a total Zope freak; I think it's by far the best application server environment out there, but the documentation has always managed to be really boggling. There's this really bizarre learning curve involved, and for some reason they've never seemed able to get past it. Once you understand Zope, it's great, but if you don't it can be pretty hellish. At least the mailing lists are generally good sources of info if you make some effort to sound like you know *sort* of what you're doing. :)
As to benchmarks and stuff, I know that there were some tests done some time ago with Zope vs. Tomcat vs. something else, but I've long since lost the links. Search the mailing list archives, should be in there. (Of course, as the advocate, I should really be the one supplying the links, eh?)
Re:zope stats (Score:2)
If the stuff is pulled from and stored to a relational DB, why not just use a language which is more suited to dealing with relational stuff? Zope seems to thrive on OOdb stuff, and the relational, while possible, is an 'oh yeah, that too' thing (again, talking appearances).
Yes, you should supply the links.
Comparing against Tomcat - at least earlier versions - is like shooting fish in a barrel. I'd be more interested to see it go against a BEA app, or a well-built PHP apps (not that many exist tho!)
Re:zope stats (Score:2)
Speaking from experience, the way Zope ties into the relational databases is anything but "oh yeah, that too." It's kind of difficult to explain how the two can work together. First off, the ZopeDB really isn't OO in the way that you're thinking it is. There's many similarities, but if you try to make it work exactly like the OO model in your head, you'll probably end up banging against some walls. When you go to http://host/foo/bar/baz, "foo" "bar" and "baz" are all objects in the ZopeDB, and they aren't necessarily "heirarchical" in the way you might think. Ie, the "directory" structure could look like this:
It's really beyond the scope of a Slashdot post to fully go into, however. :) The OO stuff is just really wicked-cool to code in.
As for the speed thing, it is really difficult to compare just because of all that Zope's doing. For every web request you make into Zope, it'll be doing authentication, persisting changes in the Zodb, doing some version control stuff, talking to the relational database, adding up all the acquisition paths and so forth . . . It's doing a *lot,* and it makes it difficult to compare to other packages because when you get to that level of complexity it becomes harder to say which is "better." Like, something might be running faster, but you don't get all the cool benefits of Zope's object acquisition, or possibly the really fine-grained level of security and permissions that Zope has built in . . . And are the replacements in the competing package "better" or "worse?" It's really hard to say. There are things you can do in Zope, programming-wise, that would be nigh-impossible in other systems, just as there are probably things in other systems that would be nigh-impossible in Zope. So it's difficult to tell.
But I'm rambling now. :)
phpclasses.org (Score:5, Informative)
Big problem with most PHP Books (Score:5, Insightful)
Re:Big problem with most PHP Books (Score:3, Insightful)
Agreed. I recently had to jump into the PHP pool, so went search for books on exactly this. I've been doing web development with perl for something like five years, know a couple other languages fairly well, and dabble in another few. So syntax and learning the language weren't an issue - I just wanted to know what the best way to use this tool was.
After spending the better part of a day researching and perusing PHP books I settled on that New Riders title, Advanced Web Development with PHP or something (don't have the book handy, I probably got the title wrong). It was written by a couple of core developers, had some stuff on the back on developing PHP itself, and a sample application or two.
Unfortunately, the book really lacked focus. No best practices were extrapolated from the example code, and only the vaguest nods toward larger architectural issues were given. It wasn't entirely useless, and it did smooth out one or two learning bumps, but it wasn't worth the cover price.
This seems to be a common unfilled niche, at least in web-related development books - titles aimed at the experienced developer who wants to get up to speed on a new tool fast, with a minimum of "this is what a TCP/IP stack is" or "here's how you use a for loop". I don't know, maybe it's because it's harder to write a good book dealing with larger, real word issues, than it is to just reprint the function reference.
Re:Big problem with most PHP Books (Score:2)
BullcrOOP!
What specific software engineering problem did OO "fix"?
OO is NOT more change-friendly. I challenge you to provide specifics. No more cliches and double-talk. Talk with code and not slOOgans.
Where's the evidence!
I might be an anti-OO troll, but I am a
*correct* troll. The BS surrounding OO is simply amazing.
Give me realistic details, and I shall slay your OO code WRT "change-friendliness". (At least break even.)
oop.ismad.com
Re:Big problem with most PHP Books (Score:2)
Well, let's see it. Without scrutiny, how do you know that your approach is the *only* way to acheive whatever it is you acheived? I have seen other OO fans do stuff where it was discovered they were not very good procedural/relational programmers (or using lame languages), and attributed their lack of skill to the paradigm being faulty.
I am not saying that you necessarily fit that profile, but that without seeing it, one cannot rule it out.
(* Besides that, it sounds like you have other problems pent up inside you. *)
OO is overhyped regardless of whatever "pent up" problems I might have. I never see good evidence; only vague cliches, mantra, and toy examples that don't fit change-patterns of the real world.
I will agree that *some* people may think better under OO, but one should not extrapolate that to all developers unless good objective evidence is presented for its alleged superiority.
Getting around personal weaknesses and/or bias of either party is why I want to see actual examples of OO being "better" than p/r. That way neither side has to take the others' word for it.
You game?
ADO for PHP (Score:4, Informative)
As someone who does database coding for PHP nearly everyday, I must say the ADO interface that can be found here [weblogs.com] has been a godsend. It makes it so easy to create database independent code with minimal overhead. Of course, this package is open source :)
Re:ADO for PHP (Score:2)
Rasmus' is the best PHP book I've ever read, (Score:3, Informative)
It's by far the most concise, useful, and down-and-dirty books I've ever read on PHP. Even the usually-useless PHP function reference in this books is a step above the norm.
The book talks about important things like PDF creation, the GD library, and how to extend PHP. Setting up and connecting to a DB is kept to a minimum. Kudos to the man.
S
question - not trolling (Score:2, Interesting)
One thing I see people say is that it can be imbedded into your html, but you can do that with Apache::ASP, and a bunch of others, I wrote one myself for my current job.
Plus, with mod_perl, you can write your own handlers in Perl, which is really great, not sure if you can do that with PHP...
But the number one advantage with Perl, IMHO, is the CPAN.
I just don't see what PHP offers that Perl doesn't already do better.
Now, please folks, I'm interested in hearing what PHP actually offers, I'm not looking for "Perl looks like line noise" or "PHP is Perl for girlies" type comments.
Re:question - not trolling (Score:2, Interesting)
For that stuff, Perl is overfeatured. Using PHP is simpler, you can embed it in your HTML with the syntax, and it makes for faster development.
For serious text processing, you can always exec perl programs, or pipe output/input to Perl daemons.
All that being said, mod_perl is wonderful, too, especially if you know the language already, or have a really complex web app.
Right tool, right job, etc.
Re:question - not trolling (Score:2)
comment [slashdot.org]
if someone posts a link to pear, keep in mind it's nowhere near as polished and feature rich as cpan.
Re:question - not trolling (Score:2)
The PHP vs Perl comparison reminds me of the C vs C++ one. The former of each is simple, almost a complete subset of the latter, and is appreciated by many as being easy to maintain. The latter of each is touted as more powerful, better OO, wider range of classes, but turn out more complex code having a higher maintenance cost.
Much like C and C++ co-exist today, PHP and Perl can also. For simple web apps, PHP is perfect. Those that know Perl can continue to use it, there is no great incentive to change. Then for sites that need massive scalability there is Java. If you know Perl, why not have a play with PHP? It's one more tool to add to your arsenal.
Phillip.
Re:question - not trolling (Score:2)
I've been using perl for web development for some time, and just this spring started using PHP. I'd looked at it as an alternative in the PHP3 days, but the lack of database abstraction turned me off. The language has come a long way since then, but there are a number of things I find awkward about it. The reason I've mostly switched to PHP (for the moment) is because a) a couple of projects that had PHP/MySQL as a requirement came up, and b) by the time those were done, I had a large reusable code base that did pretty much what I'd been planning to do with perl only a few months ago. I've got much more experience with perl, though, so add the appropriate amount of salt.
First, as far as I can tell, PHP doesn't give you any functionality that you don't get in Perl. I frequently find myself doing a lot more typing with PHP than Perl would require to do the same thing.
Second, someone here mentioned that PHP has a more focussed feature set, and is therefore easier for web development. I tend to disagree. PHP is heavily weighted towards database access, HTML manipulation, session management, etc., but at the same time there are a whole lot of functions built into the core language that, frankly, I think are superfluous. Once or twice I've come across something that I thought would be really cool if Perl had it, but my overwhelming impression was: too much in the core language. Syntactically, PHP might look easier, but if you've already mastered Perl syntax, there's no gain here.
Third, PHP is designed to be integrated into HTML. This can become largely a religious issue, but I think that's a Bad Idea, for a whole lot of reasons. I like the HTML::Template module in Perl a whole lot because it minimizes the amount of logic you can mix in with your HTML. The Xtemplate class mentioned in this article looks like it has a similar goal, but PHP as a language encourages the mixing of code and logic. It just doesn't sit right with me.
Fourth, (and some might consider this a non-issue) is that I just don't like using a function call for a regex match. I like Perl's binding operators much better.
Finally, the language is not as mature as Perl. Functions are renamed between point releases (from the array_key_exists() definition: "Note: This name of this function is key_exists() in PHP version 4.06") and major changes in the default configuration between point releases (form variables no longer auto-vivified as of PHP 4.20 (yes, I know the reasons, but I'm savvy enough to initialize my variables before use, thank you very much)). Functions are also frequently named in incosistent ways. Some use underscores in them, others interspersed caps, and functions that do similar things don't always have names constructed in a similar way (key_exists vs. all the other array_x functions isn't the best example, but I don't have any others at my fingertips. I've run into a few of them, though). This isn't confidence inspiring.
The main argument that I've heard in favour of PHP over Perl is that the length of time it takes for someone new to web programming to learn to do the same things Perl as are built in to PHP (session handling, database access, etc) is shorter. I'm not sure that I agree - I've never found it difficult to pick up a new module. But as I said, I've been using Perl for a while.
The only advantage I've personally found to using PHP so far has little to do with the language, and more the way it's deployed. I never know where a web site I develop is going to live. Unfortunately, the vast majority of hosts seem to toss on the default Perl install and call it a day. Not being able to count on, say, DBI, is a real bitch. I could say that the site requires mod_perl, DBI, the libnet bundle, etc., but a) that gets you a lot of blank stares (yes, from hosts), whereas with PHP, I know I'm getting a database, and it's probably MySQL, and various other goodies.
Tangent: One of my big hopes for Perl 6 has nothing to do with the language, but with the way it's deployed. I'm really hoping that a small core language with SDKs (a web development SDK with DBI, libnet, and Mason. yum) will encourage sysadmins to put more stuff I need on their servers. Untill that happens (or we start co-locing all our sites), I'm probably going to be using PHP for the bulk of our development. It makes me sad that I'm using a tool that, while workable, I don't find as powerful as Perl, still has a lot of rough edges, and with a far inferior toolbox (no CPAN) simply because what I often need isn't widely installed.
I've gone on enough, but I hope I've given you a bit of insight into my experiences with the two tools. PHP is servicable, but Perl really helps me. If you have control over hosting environment, stick with Perl. You'll get more mileage out of it.
embedded perl (Score:3, Informative)
http://perl.apache.org/embperl/ [apache.org]
"Gentle learning curve"? (Score:3, Interesting)
A "steep learning curve" is one where you go up, and get to the top, quickly, ie the thing is easy to learn quickly.
A "gentle learning curve" is one that you climb up slowly over a long time, ie the thing is a right pain to learn and takes ages.
So why do people who appear to know English get these the wrong way round? Is it perhaps that they're not illiterate, they're just innumerate and haven't a clue what a graph is?
Re:"Gentle learning curve"? (Score:2)
I knew even before I checked your homepage that you lived in Cambridge... where they don't have any hills. The trick to understanding the graph that you missed is that you need to stand the bit of paper on its edge. You are right about time going along the x-axis, but a steep climb is far more difficult to walk up (whether mentally or physically).
A steep learning curve is hard too learn, but will get you there more quickly. And vice versa for a gentle learning curve.
Phillip.
Re:"Gentle learning curve"? (Score:2)
A steep curve has a steep slope. Sure, it rises quickly if you're just plotting height against some horizontal variation, but if you're climbing it, actual progress can be very slow inded. A gentle curve rises slowly, but is easy to move over, so actual progress can be quicker. This becomes very clear after you've done a bit of mountain hiking, and most of us on slashdot could use some time outside, so I urge everyone to try this.
When I think steep learning curve, besides thinking of bushwhacking up Jacob's Ladder to get to Lone Peak (overlooking Salt Lake City, Heber, and Provo in Utah), I think of Finale (the music typesetting program). Holy cow, you have to fight to learn that thing.
Other option: openACS (Score:2, Insightful)
The best thing about the openACS toolkit is that you can have a functional db-backed site up in no time. No need to re-invent the wheel. :)
Web Applications (Score:2)
Yeah, I could write one myself (and in fact I am), but I'm thinking I can't be the only one thinking about this.
PHP and XML (Score:2)
There are a couple of xml modules that are veneers onto standard XML libraries, and also a good PHP Class, but all are not that easy to use. I wanted an API that took under 10 mins to learn and be competant in. You can see it here [progressiv...ishing.com]. So simple it only took me a couple of minutes to write a XML-based guestbook [homeip.net]. Another example is here [homeip.net]. Install instructions are on the site, feel free to have a try and give any feedback.
Phillip.
Stupid pedantic correction (Score:2, Interesting)
As for the book... personally I wouldn't have found it useful (based on this review) at any stage of my PHP education. The online manual is simply too good. I really don't see what else is needed - good coding practice can be figured out with common sense - a mix and match from Perl, C, and (more and more these days, especially with Zend 2) Java.
The function reference is superb - not to mention the user-contributed notes, which as often as not have the answer to your specific question. My Galeon is, not surprisingly, outfitted with a Smart Bookmark to the function reference. Beats a book any day.
Re:It's amazing how far this language has come (Score:4, Interesting)
I appreciate your pedantry (Score:1)
Re:I appreciate your pedantry (Score:2)
initially as a simple set of Perl scripts.......As more functionality was required, Rasmus wrote a much larger C implementation
Re:It's amazing how far this language has come (Score:4, Informative)
Amen to that. I would add a plug for ADODB [weblogs.com] or something similar for database abstraction, which makes PHP a bit more like the Perl DBI (no more separate sets of calls for each database type).
Next, while MySQL is great for small projects (and fast), it really is just a port of SQL to dbm files, and not truly relational, so it isn't great for large projects. As you mentioned, Postgres or Oracle fill this niche quite nicely (I don't really like the Oracle model for data types, but that is my personal bias). I could be mistaken here as I haven't used it much, but isn't Jet the file format used for MS Access databases? Access never seemed very robust to me.
JET vs. MySQL? (Score:2)
JET less crippled than MySQL? (I assume you mean MS's JET. Is there another with that name?)
It wouldn't even run if it was that bad.
The only nice thing about JET is that it is easy to transfer the database data and schema together in one file. Beyond that, it is the royal pits.
I wish an open-source JET-like engine and/or file format caught on. (But fixed)
Re:The Web is Dead (Score:2)
Re:The Web is Dead (Score:2)
They were *not* promoting MS, but merely giving their opinion that MS will kill the standards and or the market.
That is a legitamate opinion. MS has killed other things. (I don't necessarily agree with it, but it is an understandable viewpoint based on past history.)
Their sig also suggests that they are a Perl fan anyhow, and not an MS fan.
Bad moderator!
Re:Using PHP and MySQL for a website... (Score:2, Insightful)
Re:Using PHP and MySQL for a website... (Score:2, Interesting)
Re:Using PHP and MySQL for a website... (Score:2)
Plus, we don't have to take the DB offline to perform BACKUPs and other such nonsense. Replication is better and faster, java and XML support, etc. etc.. Sometimes, not always, but sometimes you get what you pay for.
Re:Using PHP and MySQL for a website... (Score:2)
They [zend.com] seem to indicate it works well. Although our site's Case Study is a bit out-dated it still provides significant value, esp. when considering the cost of a J2EE app server and the like.
Re:Using PHP and MySQL for a website... (Score:2)
Re:The book (Score:1)
Oh my god I used "has" rather then "have" on that last sentance. Also lots of bad grammer in that post. *Sarcasticly says to self* >> Perhaps its time I take another English literature that my university forces me to take. All that English literature really helps me to learn proper programming techniques.
Oh shit I'm talking to myself again.Re:The book (Score:1)
So many of my friends seem to think it's inevitable that
It's really depressing. Microsoft won the public opinion war a long time ago (a clear sign comes when you ask an average user what kind of computer they have and they answer Office 98), and now they seem to be swaying developers as well.
Re:PHP == Perl for girls (Score:3, Funny)
Re:PHP == Perl for girls (Score:2)
Perhaps in the sense that boys bust in town, knock the girl up in wild passion, then skip town and leave a cryptic mess for somebody else to take care of for the rest of the "project".
I don't care, use whatever language you like as long as you don't shuv it down other's throats.
BTW, I don't like Perl's habit of using arrays of pointers to arrays to create collections. If you have to change the implemenation of the collection to get say more columns or indexes, then you have to overhaul a bunch of code. Better to wrap collections into some scalable API so that changing the guts does not create more consulting hours to line your pockets.
Re:Why Not Java? (Score:4, Interesting)
That being said, there are a few reasons, actually. I do some development work in Java, but I'm also pretty well-versed in a variety of other languages; including C, C++, Perl, Assembly (x86 and good 'ole 68k), and PHP (and shell scripting, of course). Compared to PHP, JSP is a *pig*. It eats up a much larger chunk of memory, more CPU time, and is IMHO a terrible platform for developing small web-based applications. JSP+EJB does have its uses, but not in the arena of small webapps.
This is where PHP really shines; it's very fast, has a small footprint, and is *much* easier to use and debug than JSP is.
So, for writing huge, enterprise-level apps, JSP+EJB is the way to go. For writing smaller apps; things that need to be written quickly and securely, I'll stick with PHP.
Re:Why Not Java? (Score:2)
Ah well, I'll stick to me PHP+Postgres any day.
Re:Why Not Java? (Score:2)