Skip navigation.
Home

archives

I'm smrt.

Bad Architecture

I like to laugh at clever programmers that outsmart themselves. An anonymous user sent in the following.

<?php
/* query_fetch - a very smart function.
  It executes and fetches sql data, returning either a value, an array,
  or a multidimensional array depending on the query results
*/
function query_fetch ($query,$start=1,$max=1000)
   {
   ...
   }
?>

The WTF is what query_fetch() returns. Depending on what comes back from the database it returns a single value (1 row, 1 column), an array (1 row, multiple columns), or a multi-dimensional array (multiple rows and columns). Cool right? A single function that does all that... ohh very smart.