GarryLaly

Database Insert with Data Array

May 14th, 2014
328
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.41 KB | None | 0 0
  1. //By Garry Priambudi
  2. //Website: garrystudio.com
  3. function db_insert_array($tbl, $arr) {
  4.     $sql = "INSERT INTO $tbl ";
  5.     $sql .= "VALUES(";
  6.     $arrLength = count($arr);
  7.     $no = 0;
  8.     foreach ($arr as $val) {
  9.         $no += 1;
  10.         if ($no >= $arrLength) {
  11.             $sql .= "'$val'";
  12.         }else {
  13.             $sql .= "'$val',";
  14.         }
  15.     }
  16.     $sql .= ")";
  17.        
  18.     return $sql;
  19. }
Advertisement
Add Comment
Please, Sign In to add comment