News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Timothy Boronczyk's Blog:
Avoid Fetch-Object Abuse
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.
0 comments voice your opinion now!
fetch object mysql pdo array return value


blog comments powered by Disqus

Similar Posts

Alex Netkachov's Blog: Jamp! is Updated

Kae Verens' Blog: review: Mastering phpMyAdmin 2.11 for Effective MySQL Management

PHPBuilder.com: My Automated PHP Scripts for Creating FTP Connections to a Remote Server

Lukas Smith\'s Blog: MDB2 example

MSBWare.com: XML to Array


Community Events

Don't see your event here?
Let us know!


feature development wordpress interview threedevsandamaybe series release laravel5 community opinion framework voicesoftheelephpant unittest laravel api podcast library extension language introduction

All content copyright, 2015 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework