 | News Feed |
 | Jobs Feed |
Sections
|
| feed this: |  |
DevShed: Building an ORM in PHP
by Chris Cornutt November 18, 2011 @ 09:45:15
On DevShed today there's a new tutorial showing you how to build a basic ORM layer on top of a MySQL database. It includes all the code you'll need (cut&paste-able, not as a download).
Obviously, with so many ORMs at one's disposal for free, it seems pretty pointless to develop a custom one; are we trying to reinvent the wheel? No, of course not. But if you need to create a simple application that performs a few CRUD operations on some related domain objects and don't want to climb the learning curve of a third-party library, then implementing a custom ORM might make sense. There's alos the educational aspect of the process (yes, learning one or two things never hurts).
They start you off with the creation of the "data persistence layer" (an interface first) to connect to the database, building a MySQL-specific one on top of it. Next up is the data mapper layer making things like "fetch by ID" and the insert/update/delete possible. Their simple example doesn't include anything about ORM relationships, though - just fetching simple rows.
voice your opinion now!
orm tutorial mysql mapper fetch database
Script-Tutorials.com: How to Use APC Caching with PHP
by Chris Cornutt September 15, 2011 @ 08:29:14
On Script-Tutorials.com today there's a new article introducing you to using APC caching in your PHP applications. Their simple example sets up a caching class that handles the dirty work for you.
Today I have another interesting article for PHP. We will talking about caching, and practice of using caching in php. I will make review of APC caching and will show you how you can use APC in PHP. [...] Now people have learned to use the server memory for data storage. RAM much faster than hard disk, and the price of memory falls all the time, so let's use all these advantages of this.
Included in the post is the code for a few different files - the caching class itself that implements the APC functions in PHP and some examples of it in use: saving objects, fetching data from the cache and removing things from the cache.
voice your opinion now!
caching apc tutorial class add remove fetch
Timothy Boronczyk's Blog: Avoid Fetch-Object Abuse
by Chris Cornutt July 12, 2011 @ 12:10:02
In a new post on his blog Timothy Boronczyk has a recommendation for developers working in PHP with databases that have a "fetch object" method - use it correctly or avoid it all together.
Lately I'm finding a lot of instances of the mysql_fetch_object() function being used in a particular codebase I help maintain. Unfortunately, I've yet to see it used correctly. It always seems to be used to retrieve a stdClass object from a query result where mysql_fetch_array() or mysql_fetch_assoc() would be the more appropriate choice.
Most of his complaint is that, despite pulling out the data as an object, most scripts continue to use it like you would an array, looping over it. There's extra overhead generated from the object creation that could cause issues, especially with large return data sets.
The best advice I can offer is to educate yourself and others how the function should be used so its abuse isn't perpetuated. Then, be cautious when using mysql_fetch_object() correctly and understand the process it follows to create and return an object. If not for yourself, then do it for the kittens.
voice your opinion now!
fetch object mysql pdo array return value
Gonzalo Ayuso's Blog: Performance analysis fetching data with PDO and PHP.
by Chris Cornutt March 28, 2011 @ 08:12:20
Gonzalo Ayuso has a new post to his blog today with the results of some performance analysis he ran when fetching data with PHP and PDO.
Fetching data from databases is a common operation in our work as developers. There are many drivers (normally I use PDO), but the usage of all of them are similar and switch from one to another is not difficult (they almost share the same interface). In this post I will focus on fetching data.
He includes his sample scripts - one using just fetch() and the other using fetchAll() - that include some timing and memory checking logic and includes the results of his "limit 10000" queries from his tables. Not surprisingly, the fetchAll required more memory than the fetch call. Event changing it to a loop of fetch() methods results in about the same amount of memory as a fetchAll.
voice your opinion now!
performance analysis benchmark pdo fetch fetchall memory
Brian Moon's Blog: PHP 5.3 and mysqlnd - Unexpected results
by Chris Cornutt August 05, 2010 @ 10:33:01
On his blog today Brian Moon takes a look at the mysqlnd driver that comes with PHP 5.3 by default and some strangeness he found when trying to fetch results.
I have spoken in the past (see my slides and interview: MySQL Tips and Tricks) about using mysql_unbuffered_query or using mysqli_query with the MYSQLI_USE_RESULT flag [...] So, my natural thought was that using MYSQLI_USE_RESULT with fetch_all would yield the most awesome performance ever. The data would not be buffered and it would get put into a PHP array in C instead of native code.
He had hoped that the fetch_all would cooperate with the MYSQL_USE_RESULT setting, but it seemed to only work with the MYSQLI_STORE_RESULT default. He even filed a bug on the matter which was marked bogus and then reopened. He hopes to show, based on test results, that the result could be much faster.
voice your opinion now!
mysqldn fetch results bug performance
Lorna Mitchell's Blog: Introduction to Zend_Db
by Chris Cornutt October 31, 2008 @ 12:57:07
Lorna Mitchell has an introduction to Zend_Db, the Zend Framework database abstraction layer posted to her blog today:
I recently worked on a project which was based on Zend Framework - I haven't worked with it before and I was temporarily confused by the existing implementation of some of the database-level stuff. After much reading and untangling of code, I'm now pretty clear how this should look, so here's my overview. I'm not going to go into setting up a whole application, but this is a quick primer on how data models go together.
She talks about table modeling, fetching rows/data from the model and working with rows/rowsets.
voice your opinion now!
introduction zenddb database zendframework fetch row rowset
Jani Hartikainen's Blog: Understanding Doctrine's NestedSet feature
by Chris Cornutt September 02, 2008 @ 10:29:56
On his CodeUtopia blog Jani Hartikainen gives an inside look at a feature of Doctrine, nested sets.
The Doctrine library comes with a feature called nested set, which makes saving trees in a database easy. However, it's quite easy to accidentally cause a lot of extra unneeded queries if not being careful. Here are some pointers to keep in mind while working with the nested set, and some example queries to make understanding it easier.
He gives an example, showing how to get rows from the database - parent and child - and some optimization tips to keep things light. There's also some pros and cons included for doing it either way (the standard fetching or using the more optimized versions).
voice your opinion now!
doctrine nestedset feature fetch database row parent child
|
Community Events
Don't see your event here? Let us know!
|