MongoDB and PHP
By Steve Francia
(O’Reilly, paperback, list price $19.99; Kindle edition, list price, $14.99)
You can’t blame Steve Francia for being vocal in his praise for MongoDB®. He’s the chief solutions architect at 10gen, Inc., which develops and supports this well-respected document-oriented database.
One consequence of the current, explosive growth of social media is that “all data and experience [needs] to be personalized – on a large scale,” he writes in his new book, MongoDB and PHP. Today, the data stores and caching techniques used over in the past three decades are losing their ability to keep pace. So: “It was out of this need that MongoDB was created. A database for today’s applications, a database for today’s challenges, a database for today’s scale.”
MongoDB, according to its 10gen, Inc., website, is “a scalable, high-performance, open-source noSQL database,” written in C++. Its features include: document-oriented storage; full index support; replication and high availability; auto-sharding (horizontal scaling with a partitioning architecture); querying; rapid in-place updates; map/reduce (for batch processing of data and aggregation); and GridFS (a specification for storing large files in MongoDb).
Francia explains that MongoDB is a document database. “At the highest level of organization, it is quite similar to a relational database, but as you get closer to the data itself, you will notice a significant change in the way the data is stored. Instead of databases, tables, columns, and rows, you have databases, collections, and documents.”
Meanwhile, in PHP (PHP: Hypertext Processor), “a document is equivalent to an array …,” for all intents and purposes.
PHP, which can be downloaded from this site, “is a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML,” according to the PHP Group.
Francia notes in his book that “[i]n MongoDB, the primary object is called a document. A document doesn’t have a direct correlation in the relational world. Documents do not have a predefined schema like relational database tables. A document is partly a row, in that it’s where the data is located, but it’s also part columns, in that the schema is defined in each document (not table-wide)….The best way to think of a document is as a multidimensional array.”
Meanwhile, Francia adds: “Documents map extremely well to objects and other PHP data types like arrays and even multidimensional arrays.” So PHP users contemplating building PHP applications with MongoDB will find that “the PHP array has the closest correlation of any data type. It’s nearly a 1-to-1 correlation.”
His code examples, illustrations and succinct paragraphs show how MongoDB and PHP can work together closely and effectively when building database applications.
If you have been contemplating diving into PHP and/or MongoDB, this is a worthy book to add to your learning and reference collections.
– Si Dunn is a novelist, screenwriter, freelance book reviewer, and former software technical writer and software/hardware QA test specialist. He also is a former newspaper and magazine photojournalist. His latest book is Dark Signals, a Vietnam War memoir available soon in paperback. He is the author of a detective novel, Erwin’s Law, a novella, Jump, and several other books and short stories.