Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function inserer_donnes($donnees,$table)
- {
- $champs_existants = array();
- $requete_colonnes = 'SHOW COLUMNS FROM '.$table;
- $resultat_colonnes = mysql_query($requete_colonnes) or die(mysql_error());
- while ($colonne=mysql_fetch_array($resultat_colonnes))
- $champs_existants[] = $colonne[0];
- $champs = array();
- $valeurs = array();
- foreach($donnees as $cle => $valeur)
- {
- if (!empty($valeur) and in_array($cle,$champs_existants))
- {
- $champs[] = $cle;
- $valeurs[] = '"'.htmlspecialchars(is_array($valeur)?'|'.implode('|',$valeur).'|':$valeur,ENT_QUOTES).'"';
- }
- }
- if (count($champs)>0)
- {
- $requete = 'INSERT INTO `'.$table.'` (`'.implode('`,`',$champs).'`) VALUES ('.utf8_decode(implode(',',$valeurs)).')';
- mysql_query($requete) or die(mysql_error());
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement