Slashdot Mirror


MySQL and Perl for the Web

Craig Maloney writes "MySQL (love it or hate it) is one of the most popular databases for deploying websites. Perl (also love it or hate it) was almost synonymous with website programming. Arguably there are different choices for different needs in web development (PostgreSQL, PHP, Java, etc.), but there is no argument that if you are planning on putting together a website, using MySQL and Perl that MySQL & Perl for the Web will aid immensely in that development." Read on for the rest of Maloney's concise review of the book. While not new, he says it's still a valuable volume. MySQL and Perl for the Web author Paul DuBois pages 552 publisher New Riders rating 10 reviewer Craig Maloney ISBN 0735710546 summary A clear, well written book for Perl and MySQL

Who is this book for? Developers looking for a quality book on Perl and database development should not pass this book up. While the title of this book is MySQL & Perl for the Web, it could have easily been called DBD/DBI & Perl for the Web. The SQL examples may or may not work with various databases, but the DBI interface code should remain the same. This book will also do well as a reference for experienced coders looking for well-crafted examples of web-based applications. What's good? The second chapter should be enough to get anyone up to speed with using Perl, DBI, CGI, Apache, and MySQL. After a brief introduction and configuration of MySQL and Apache, the author settles in to discuss coding DBI and Perl. The remainder of the chapter details the best practices for using Perl and DBI together. Near the end of the second chapter, the author creates a fully functional to-do list, demonstrating ways to add, update, and delete information from the database using Perl and DBI. Instead of taking small baby steps over many chapters, the author shows important concepts and best practices for those concepts quickly. Even seasoned (hardened?) programmers may learn new tricks or methodologies from the second chapter of this book.

Is that the end? Are we left with one very well written tutorial chapter? Thankfully, the rest of the book has plenty to offer. Subsequent chapters include:

  • Improving performance with mod_perl
  • Generating and processing forms
  • Writing form-based applications
  • Automating the form-handling process
  • Performing searches
  • Session management
  • Security and privacy issues
  • E-commerce applications

Each chapter is clearly written, with several examples used to demonstrate the concepts presented. The examples are clearly written, and the author makes the whole learning process enjoyable and fun. The examples range from a give-away contest (including a random drawing), an electronic greeting card program, polling programs, and a shopping cart program. Each of the examples is presented completely, but are introduced in pieces (subroutines, modules, etc.) The full source code is available from the author's website at http://www.kitebird.com/mysql-perl/

What's in it for me? MySQL & Perl for the Web is the book that Perl programmers on any project will wish The Other Guy had read. The examples are clear, the writing is engaging, and the code is maintainable. This is a practical book and should not be overlooked in any serious Perl programmer's library.

You can purchase MySQL and Perl for the Web from bn.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.

27 of 244 comments (clear)

  1. Web, schmeb by jargoone · · Score: 5, Insightful

    Perl (also love it or hate it) was almost synonymous with website programming.

    Love Perl for most anything, hate it for web "programming". There's a good reason it was synonymous with website programming. It's because there now exist more flexible, robust, easy-to-use platforms for web development.

    1. Re:Web, schmeb by wawannem · · Score: 4, Interesting

      Currently working in a Java/JSP/Sybase-based web programming environment and I love it.

      But, I will give perl it's props.

      I often use it to prototype large projects. Despite most arguments for other languages, I will say that you can pump out perl code pretty fast and it does help when you need some mockups and basic functionality to sell a concept.

    2. Re:Web, schmeb by zerocool^ · · Score: 3, Informative


      ?? Support your inferrence that perl is faster than PHP?

      I don't have hard numbers, but I have been in environments where both are used, and perl seems to perform much worse. Specifically, I administer ~100 webservers, and clients that use more php put far less of a load on the system than people writing in perl scripts executed through web pages or mod_perl. In multiple years of working with both, perl just has become synonymous with higher system load.

      The load jumps related to PHP that I see are always MySQL based loads.

      ~Will

      --
      sig?
    3. Re:Web, schmeb by Etyenne · · Score: 5, Funny

      It well-known indeed that the plural of anecdote is data.

      --
      :wq
    4. Re:Web, schmeb by consumer · · Score: 3, Interesting

      Frankly, if PHP outperformed mod_perl on your system it was probably because of mistakes in the Perl code. Even PHP boosters admit that mod_perl is faster, as in this talk from Yahoo.

    5. Re:Web, schmeb by sporty · · Score: 4, Informative
      No. perl is not a regexp manip language. The regular expression stuff is a subset of it, just like the data structures and what not.


      Saying that perl had to be addapted to web development is just wrong. perl also, is not slower than php. Perl is a VERY modular language. You can do traditional CGI programming in it, just like php. There are many templating options as well as mod_perl, which more resembles java servlets than it does php.


      Also, stating that it's clearer means nothing. At least with DBI, i know how to connect to any database. With php, there's a seperate function to open a connection to the database, per vendor. Their function names are quite conveluded, switching orders of word types, i.e. noun_verb vs verb_noun.


      PHP is built for the web first, and is a programming language second.

      --

      -
      ping -f 255.255.255.255 # if only

    6. Re:Web, schmeb by daperdan · · Score: 3, Interesting

      Maybe you should qualify your statement with: PHP is faster than a perl script executed out of a /cgi-bin/ directory without any accelerators. You'll find benchmarks all over the place that will show you that mod_perl out performs php in most cases.

      http://www.bagley.org/~doug/shootout/

      This is old info but it does show that php's scripting engine has room for improvement.

      Ultimately, when you consider the price of memory and processor speed, it doesn't really matter.

    7. Re:Web, schmeb by ajs · · Score: 3, Interesting

      Perl had to be adapted to web development

      No more so than any other language. PHP really doesn't count here... it's an HTML templating tool that was adapted to programming, which is why it's great for prototyping small web tools, but even at the medium-scale (e.g. PHPNuke/PostNuke) it's already cumbersome in the extreme (look at how many times those two projects have had to re-architect). Insofar as PHP is getting back to its roots and becoming Perl again, it's a good language.

      If I were starting from scratch on a new Web-related project I might use PHP, but I would almost certainly treat it as a templating system only, and then write the back-end in Perl or Java depending on the platform. But that might just be that I've not explored TTK enough... I've heard very good things about it as a templating system.

      it's significantly slower than php

      No, no it's not. Running any kind of benchmark on real code it's not. When you integrate Perl poorly with a Web server, then it's slow. When you integrate it well (e.g. bricolage, TTK, Mason) it's quite reasonable, and VERY easy to develop in.

      [PHP is] easier to understand and easier to program in

      well ... to a PHP programmer yes.

      PHP is a Perl derivative in roughly the same way that Java is a C++ derivative. One's children always spend their youth claiming that their parents "did it all wrong", but as they grow and mature they find that their parents had gone through all of this before and that their decisions were not so very surprising after all. PHP has come a long way, and bravo to it, but let's not get hyperbolic.

      Familiarity with perl (slashdot)

      Were you using Slash as an example of something written by someone familliar with Perl or as an example of something one would be familliar with?

      If the former, it probably should have been "Familiarity with Perl and PHP not having been written yet (Slashcode)"

    8. Re:Web, schmeb by Doyle · · Score: 3, Informative
      In multiple years of working with both, perl just has become synonymous with higher system load.

      Here are some benchmarks you might find interesting. Particularly:
      The results of PHP were not what we expected. Being exposed to the hype that rules on the Internet about PHP, we expected it to be at least at the second place. It did not scale well (see BENCH4) and exhausted system processing power when it run, leaving it unusable. We must admit that PHP is tightly linked to MySQL, which was not how we used it, but it is our belief that a fast system can be fast irrelevant its environment.

      You can see from the graphs that mod_perl performs way better than PHP on the whole, and places less load on the server than PHP. They were not using MySQL.

  2. Re:guffaw by Neil+Blender · · Score: 3, Insightful

    "Website programming".

    Tee-hee. I still laugh when I see that phrase.


    Heh, not every website is a 50 line PHP hack made by a kid. You can do extremely powerful things with a website and those things can require complex programming skills. And that programming can be done in Perl.

  3. Re:Three cheers for LAMP by rainman_bc · · Score: 3, Informative

    the P in LAMP stands for PHP not Perl. PHP and MySQL are a perfect fit. Perl and Mysql are a real PITA.

    --
    09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0
  4. Perl / MySQL CMS solution. by Archangel+Michael · · Score: 3, Informative

    I have been using a MySQL / Perl solution called WebGUI for quite a while
    now. It is a full CMS system that is truly open source and cross
    platform, running on *nix, Windows and MacOS.

    It truly is powerful yet very easy to use. Plenty of features such as Submissions system, Bulletin Board, Calendar, Syndicated Content and much more.

    If you are looking for such a solution, feel free to give it a try.

    --
    Agent K: A *person* is smart. People are dumb, stupid, panicky animals, and you know it.
  5. I used to enjoy coding in Perl… by Anonymous Coward · · Score: 5, Funny

    ...until I discovered poking myself with a sharp stick.

    1. Re:I used to enjoy coding in Perl… by Anonymous Coward · · Score: 3, Funny
      You know you've been coding in Perl too long when...
      • It starts to look like line noise.
      • You start copying line noise into your perl scripts.
      • The scripts still work.
  6. old book? by inf0c0m · · Score: 5, Informative

    does anyone else realize that this book is exteremly old?

    Paperback, August 2001

    also.... on the same bn site

    A new copy is not available from Barnes & Noble.com at this time.

  7. Comment removed by account_deleted · · Score: 3, Funny

    Comment removed based on user account deletion

  8. Re:Pathologically Eclectic Rubbish Lister by Daniel+Dvorkin · · Score: 5, Funny

    I can think of nothing more likely to start a flamewar on /. than singing the praises of Perl and MySQL in the same story.

    <1/2 g>

    --
    The correlation between ignorance of statistics and using "correlation is not causation" as an argument is close to 1.
  9. For those getting started with Perl... by CaptainPinko · · Score: 3, Informative

    Nice. I'm planning on learning how to tie scripting (have decided on Perl yet but it's a contender) and databases this summer anyway. This book might make the decision as to what to use for me.



    However, for those just picking up Perl for the first time I recommend the free ebook Picking Up Perl, and the ActiveState Perl Interpreter for Windows (this was a while ago-- if you are using Linux it probably aleraday has Perl installed). And then as it was Windows I was learning Perl on I used OpenPerl IDE. For Linux I recommend using Kate and Konsole.



    Not trying to be off-topic here but I figure someone reading this may want to try out what this Perl thing is.



    Disclaimer: Not a Perl fan at all, I actually perfer Python, but to each their own and as any Perl hacker can appreciate TIMTOWTDI! ;)

    --
    Your CPU is not doing anything else, at least do something.
  10. one thing perl did right by jd142 · · Score: 3, Insightful

    One thing that Perl has going for it that PHP doesn't is that it has correctly set up the database connection functions. Once you connect to a data source, all of the commands you use to interact with that connection are the same, whether you are using mysql, postgresql, or just a csv file. This means that you can change backend databases trivially, merely by changing one line of code.

    With php, the commands for connecting to a database and running a query change, sometimes drastically, depending on the database you are using. For example, until recently if you had a query to run on a mysql backend, you did mysql_query($query) but for a postgres it was pg_exec($query). That is changing at least so now it's pg_query($query) but it still makes changing backends a large search, replace, and hope nothing breaks task.

    1. Re:one thing perl did right by rainman_bc · · Score: 3, Informative

      Not true. There's database layers for PHP you can use that'll make your database connections heterogeneous...

      ezSQL is one that comes to mind. There's plenty more.

      --
      09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0
  11. Re:Three cheers for LAMP by Monkey+Angst · · Score: 5, Funny
    Hitler also changed the world forever. What's your point?

    How the hell do you Godwin a thread about a Perl book?
    --
    stripShow - Where WordPress meets webcomics
  12. Why actually choose MySQL? by jesterzog · · Score: 4, Interesting

    Arguably there are different choices for different needs in web development (PostgreSQL, PHP, Java, etc.), but there is no argument that if you are planning on putting together a website, using MySQL and Perl that MySQL & Perl for the Web will aid immensely in that development.

    Maybe so, but I still have trouble figuring out why MySQL is given so much credibility in the first place.

    In the previous story about MySQL, I posted a comment asking what it actually did that other databases (including the also-free PostgreSQL) didn't do at least as well, or better. The main responses seemed to include:

    • MySQL being the only DB supported for an application that someone wanted.
    • People already being very familiar with MySQL's strange ways of doing things that are inconsistent with every other respected database, not to mention SQL standards.
    • No other free databases having reliable Windows builds. (A Windows build of Postgres is on the way, but not yet fully complete.)
    • ISP's only providing a MySQL server.
    • Simply not knowing anything else due to past experience.

    The Windows build issue seems quite reasonable, but the other reasons imply that the main reason MySQL is so popular is simply due to lock-in. People use it because they have to, or because they're not familiar with the alternatives --- not necessarily because it's actually better for the task-at-hand.

    Perhaps MySQL is such a common name that people haven't heard of better alternatives out there. Presumably the book that this story reviews, which gives it even more publicity, is yet another reason that someone might consider MySQL without even thinking about alternatives.

    Can anyone tell me if I've missed anything, though? Besides the typical lock-in reasons for using MySQL, does it actually do anything better than other databases as any sort of killer feature?

    If not, and if you're looking to start learning about a database and actually have a choice, it seems that you're much better off looking at an alternative database.... whether it be a free one such as Postgres, or one of the big ones such as Oracle or SQL Server. At the very least, you'd get a more reliable database than MySQL, a more portable database than MySQL, and even postgres (just as free) offers a wealth of additional -- often useful and important -- features such as stored procedures and more complete data integrity. You'll probably also become much more familiar with correct SQL syntax ... for what it's worth.

    1. Re:Why actually choose MySQL? by Thorizdin · · Score: 3, Insightful

      How about MySQL actually accomplishes what I want to do for a reason?

      I love people screaming that the tool I am using is wrong, when they have no idea of just what I am doing. We also use Oracle, where needed, but we run MySQL 24/7/365 in an incredibly mission critical spot and are very satisfied with it. We tried other DB's and technologies including:

      LDAP (Open and Sun/Netscape's)
      Oracle
      Postgres
      Informix (Ok we still had a license and were bored :)

      and none of them offered any better stability and only LDAP matched the performance in reads. Writes MySQL blew LDAP away so thats what we run. since we need good read & write speed.

      As for what MySQL does better? Thats easy speed. The team started with that as its goal and kept performance in their sights the entire time. The pushed back other things, like row level locking, sub-selects, and views expressly for the purpose of running quickly. This is obviously not the right approach for some applications, but for most database driven web sites it makes perfect sense. Honestly, how many web sites really need triggers and stored procedures? There is a reason that LAMP has changed small/medium web site development business, and while its not right for all sites its a perfect fit for the vast majority.

    2. Re:Why actually choose MySQL? by iwadasn · · Score: 4, Interesting

      Something I think I'll point out. If you want a little toy database, consider HSQL. It's about as good of a database as MySQL (give or take), but it's written in Java (runs on anything), is about 300k or so in size, takes all of ten seconds to set up, and is actually much more SQL compliant than MySQL.

      If a tiny easy to use database is all that you need, HSQL is for you. The one real gotcha though is that it can't handle datasets larger than 1/2 a GB. That's way too small for real database servers, but more than enough for most websites, even many commercial ones, I imagine.

      In addition, HSQL can run within your java apps, which is really nice. I usually go for a dual pronged approach. use HSQL to handle all the file BS that you app might need (various config parameters, a small data cache that can be sifted efficiently in lots of different ways, other nastiness) and as (small) test databases to try a new idea.

      For real DB work though, trade up to Postgres, and be sure to get 7.4, the 7.3.x line has a lot of crippling bugs.

      The one real gripe I have about Postgres, is god, these people are in love with Hash joins. Any really good database should avoid hash joins like the plague unless it can guarantee that all the data that could possibly be returned by a subquery will fit into RAM. Postgres often wildly mis-estimates the size of a sub query, decides to hash it, and then gets killed when the query returns 100,000 rows, rather than 100.

      A real database using a hash join when it doesn't know that it can take the whole table into RAM (if needed) is just begging to get run over. This is one of the few things that can really knock out an otherwise good database, and really should be considered more carefully. Hashjoins are for small reference data tables (few thousand rows), and should not be used unless you're guaranteed to be surprised.

      HSQL of course doesn't have this problem, because it doesn't mess around with these "big" tables that are all the rage nowadays.

  13. Perl synonymous? by Laptop+Dancer · · Score: 3, Insightful
    Perl (also love it or hate it) was almost synonymous with website programming. Arguably there are different choices for different needs in web development..
    I'm willing to argue vociferously with that!
  14. Rooting by ryantate · · Score: 4, Funny

    The only reasons to use perl over PHP for web development are 1.) familiarity with perl (slashdot), and 2.) security (to avoid "today's php upload root exploit").

    So PHP is ideal unless, you know, you don't want to be rooted ...

    Noted.

    (Backs away slowly ...)

  15. Why mysql? OR perl for that matter? by kuzb · · Score: 3, Informative

    IMO Perl is rapidly losing steam due to the enormous popularity of PHP. PHP is easier to learn, faster to master and less confusing to begin with. Not to mention, PHP's online documentation is really hard to beat sporting many easy to follow examples, a very functional layout, and features (such as the http://php.net/ search) that i'm pretty sure i've only seen mysql.com adopt.

    Granted, PHP is not great for everything, but for small to medium websites (and arguably large websites as well, I know of some corporations that use PHP, see bravenet.com, one of the largest providers of ready-to-run webmaster tools. They use PHP quite extensively.). For rapid application development, it's a dream.

    As we come closer to PHP5 (which is RC2 now) we're also seeing the integration of sqlite as an option which may appeal to people who just want to write small blogs and other applications which simply do not demand the need of mammoths like mysql or postgresql. This means less headache for budding programmers, and easier migration of applications since sqlite does not require an SQL server.

    --
    BeauHD. Worst editor since kdawson.