Location: PHPKode > scripts > AL's simple MySQL record control class > als-simple-mysql-record-control-class/al_simple_mysql_function.php
<?php

class Datacontrol{

function check_duplicate($table_name,$field_name,$field_value){
$query="SELECT * FROM $table_name WHERE ";
for($c=count($field_name);$c>0;$c--) {
  $arg=$c-1;
  $field_value[$arg]=trim($field_value[$arg]);
  $query.=" ".$field_name[$arg]."='".$field_value[$arg]."' ";
  if($c-1!=0){
    $query.=" AND ";
  }
}
//echo $query;
  $result = mysql_query($query) or die("error check_duplicate");
  if(mysql_num_rows($result)>0){
    return 1;
  }else{
    return 0;
  }
}

function filtering_record($table_name,$field_name,$field_value){
  $query="SELECT * FROM $table_name WHERE ";
for($c=count($field_name);$c>0;$c--) {
  $arg=$c-1;
  $query.=" ".$field_name[$arg]."='".$field_value[$arg]."' ";
  if($c-1!=0){
    $query.=" AND ";
  }
}
  $result = mysql_query($query) or die("error check_duplicate");
  if(mysql_num_rows($result)>0){
    return $result;
  }else{
    return 0;
  }
}

function update_record($table_name,$field_name,$field_value){
  $query="UPDATE $table_name SET ";
for($c=count($field_name);$c>0;$c--) {
  $arg=$c-1;
  $query.=" ".$field_name[$arg]."='".$field_value[$arg]."' ";
  if($c-1!=0){
    $query.=" , ";
  }
}
  $query.=" WHERE $this->id_field_name = '$this->id_field_value'";
//echo $query;
  mysql_query($query) or die("error update_record");
  if(mysql_affected_rows()>0){
    return 1;
  }else{
    return 0;
  }
}

function insert_record($table_name,$field_name,$field_value){
$query="INSERT INTO $table_name SET ";
for($c=count($field_name);$c>0;$c--) {
  $arg=$c-1;
  $query.=" ".$field_name[$arg]."='".$field_value[$arg]."' ";
  if($c-1!=0){
    $query.=" , ";
  }
}
//echo $query;
  $result = mysql_query($query) or die("error add_record");
  if(mysql_affected_rows()>0){
    return 1;
  }else{
    return 0;
  }
}

function delete_record($table_name,$field_name,$field_value){
$query="DELETE FROM $table_name WHERE ";
for($c=count($field_name);$c>0;$c--) {
  $arg=$c-1;
  $query.=" ".$field_name[$arg]."='".$field_value[$arg]."' ";
  if($c-1!=0){
    $query.=" AND ";
  }
}
//echo $query;
  $result = mysql_query($query) or die("error delete_record");
  if(mysql_affected_rows($result)>0){
    return 1;
  }else{
    return 0;
  }
}

} //end class dataControl
?>
Return current item: AL's simple MySQL record control class