Friday, April 4, 2008

SQL operation function

/* ==================================
SQL operation function by http://php-busy.blogspot.com
================================== */

// Insert function
function insert($sField,$sValue,$sTable)
{
$sql = "INSERT INTO $sTable ($sField) VALUES ($sValue)";
$result = mysql_query($sql);
return $result;
}

// Delete fucntion
function delete($sTable,$cCondition)
{
$sql ="delete from $sTable $cCondition";
$result = mysql_query($sql);
return $result;
}


// Update function
function update($sTable,$cCommand,$cCondition)
{
$sql = "UPDATE $sTable SET $cCommand $cCondition";
$result = mysql_query($sql);
return $result;
}

// Select function
function select($sTable,$cCondition)
{
$sql = "select * from $sTable $cCondition";
$query = mysql_query($sql);
$result= mysql_fetch_array($query);
return $result;
}

// num rows function
function numRows($sTable,$cCondition)
{
$sql = "select * from $sTable $cCondition";
$query = mysql_query($sql);
$nrows = mysql_num_rows($query);
return $nrows;
}
?>

No comments: