Jump to content

Recommended Posts

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;
}

Link to comment
https://forums.phpfreaks.com/topic/181951-wtf/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/181951-wtf/#findComment-959749
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.