Advertisement
Wolfrost

PHP bullshit with MySQL

Aug 30th, 2016
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.63 KB | None | 0 0
  1. /*
  2.     $t = Nome della tabella
  3.     $r = Array che conterrà i nomi dei campi da popolare (non può essere vuoto)
  4.     $v = Array che rappresenta i valori che andranno a popolare i campi (coesiste con $r)
  5. */
  6. public function InsertData($t, $v, $r = null)
  7. {
  8.     if (isset($this->active))
  9.     {
  10.         $istruzione = "INSERT INTO " .$t;
  11.         if ($r != null)
  12.         $istruzione .= " (".$r.")";
  13.                
  14.         for ($i = 0; $i < count($v); $i++)
  15.         {
  16.             if (is_string($v[$i]))
  17.                 $v[$i] = '"'.$v[$i].'"';
  18.         }
  19.         $v = implode(',',$v);
  20.         $istruzione .= " VALUES (".$v.")";
  21.                
  22.         $query = mysql_query($istruzione) or die(mysql_error());
  23.     }
  24.     else
  25.     {
  26.         return false;
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement