vendredi 9 juin 2017

multiple if vs separate database query

1.  $sql = "UPDATE table_name SET";
2.
3.  foreach($array as $key => $val){
4.      if($key == 'abc')
5.          $val = 'test';
6.      $sql .= $key . " = '" . $val . "' ";
7.  }
8.
9.  $sql .= "WHERE primary_key = 2";

Will that better to check the value in the foreach loop (line#4-5)? or to run the separate Update query?

OR

1.  $sql = "UPDATE table_name SET";
2.
3.  foreach($array as $key => $val){
4.      $sql .= $key . " = '" . $val . "' ";
5.  }
6.
7.  $sql .= "WHERE primary_key = 2";
8.  
9.  $sql = "UPDATE table_name SET abc = 'test'";

*This is a generic example, please ignore the typo and thanks in advance.

Aucun commentaire:

Enregistrer un commentaire