unkwntech Posted November 18, 2009 Share Posted November 18, 2009 I just found this <sarcasam> wonderful </sarcasam> piece of code in a project I am taking over.... Is it just me or is this really as much of a WTF as I think it is? function db_connect() { global $db_host, $db_user, $db_pass, $db_name, $db_connection; $db_connection = mysql_connect($db_host, $db_user, $db_pass) or die(mysql_error()); mysql_select_db($db_name,$db_connection); return $db_connection; } function command($sql){ if(db_connect()) $result = mysql_query($sql) or die(mysql_error()); return $result; } function query($table,$fields,$values,$request) { global $db_connection; if($request=="Add") { $command="insert into " . $table ." (" .$fields .") values(". $values . ")"; } else if($request=="Update") { $update=updateClause($fields,$values); $command="Update ". $table ." set ". $update ."where ". $_SESSION["whereClause"]; } //print $command; $result = mysql_query($command) or die(mysql_error()); //echo $result; //return $result; } function updateClause($fields,$values){ $i=0; $fieldArray=split(",",$fields); $valueArray=split(",",$values); foreach($fieldArray as $key) { $i++; } for($j=0;$j<$i;$j++) { $update1 .=$fieldArray[$j] . "=" . $valueArray[$j] . ", "; } $update1 .=":"; list($update,$a)=explode(", :",$update1); return $update; }//end function function row_count($result) { $numrows = mysql_num_rows($result); return $numrows; } function db_getrow($result) { $getrow = mysql_fetch_row($result); return $getrow; } function db_getarray($result) { $getarray = mysql_fetch_array($result); return $getarray; } function data($result) { $getarray = mysql_fetch_array($result,MYSQL_ASSOC); return $getarray; } function db_getfield($result,$field) { $getfield = mysql_fetch_field($result,$field); return $getfield; } function db_error() { $error = mysql_error(); return $error; } function dbclose($db_connection) { mysql_close($db_connection); } function flipdate($dt, $seperator_in = '-', $seperator_out = '-') { return implode($seperator_out, array_reverse(explode($seperator_in, $dt))); } function get_column($sql) { $result = mysql_query($sql) or die(mysql_error()); $row = mysql_fetch_row($result); return $row[0]; } function get_row($sql) { $result = mysql_query($sql) or die(mysql_error()); $row = mysql_fetch_array($result, MYSQL_ASSOC); return $row; } Quote Link to comment https://forums.phpfreaks.com/topic/181951-wtf/ Share on other sites More sharing options...
Alex Posted November 18, 2009 Share Posted November 18, 2009 Nearly 100 lines of more or less creating alias functions.. wonderful. Unfortunately this happens a lot. Quote Link to comment https://forums.phpfreaks.com/topic/181951-wtf/#findComment-959733 Share on other sites More sharing options...
oni-kun Posted November 18, 2009 Share Posted November 18, 2009 It's easier to learn code, than to write code. It's just pointless. Quote Link to comment https://forums.phpfreaks.com/topic/181951-wtf/#findComment-959735 Share on other sites More sharing options...
mikesta707 Posted November 18, 2009 Share Posted November 18, 2009 is there a problem or is this just about how crappy that code is? if its the latter, than yes I do agree Quote Link to comment https://forums.phpfreaks.com/topic/181951-wtf/#findComment-959740 Share on other sites More sharing options...
unkwntech Posted November 18, 2009 Author Share Posted November 18, 2009 No there is no problem other then the WTF, I havn't seen/written code like this is several years, and I'm suprised by it. This code comes from a group of 'senior developers', but I warned him no to outsource. Quote Link to comment https://forums.phpfreaks.com/topic/181951-wtf/#findComment-959747 Share on other sites More sharing options...
mikesta707 Posted November 18, 2009 Share Posted November 18, 2009 some of the functions are... ok.. i guess. but functions like this function db_getrow($result) { $getrow = mysql_fetch_row($result); return $getrow; } is just pointless.. they could have even just done this function db_getrow($result) { return mysql_fetch_row($result); } which really shows you how pointless it is. Oh well, no loss Quote Link to comment https://forums.phpfreaks.com/topic/181951-wtf/#findComment-959749 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.