Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentes Révision précédente Prochaine révision | Révision précédente | ||
| info:mysql:phpcgimysql2xml [2023/03/20 14:51] – supprimée - modification externe (Unknown date) 127.0.0.1 | info:mysql:phpcgimysql2xml [2023/03/20 14:52] (Version actuelle) – radeff | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| + | ====== phpCgiMysql2xml ====== | ||
| + | utiliser un cgi php appellé depuis php+apache, marche nickel - sauf vitesse! chercher autre solution... | ||
| + | test.php: le fichier à appeller par http / apache | ||
| + | <code php> | ||
| + | <?php | ||
| + | $dest = ' | ||
| + | |||
| + | class MySQLDump { | ||
| + | /** | ||
| + | * The backup command to execute | ||
| + | * @private | ||
| + | * @var string | ||
| + | */ | ||
| + | var $cmd; | ||
| + | |||
| + | /** | ||
| + | * MySQLDump constructor | ||
| + | |||
| + | * @param string dest (Full destination directory path for backup file) | ||
| + | * @access public | ||
| + | */ | ||
| + | | ||
| + | $this-> | ||
| + | } | ||
| + | |||
| + | |||
| + | /** | ||
| + | * Runs the constructed command | ||
| + | * @access public | ||
| + | * @return void | ||
| + | */ | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | } | ||
| + | } | ||
| + | |||
| + | // Instantiate MySQLDump | ||
| + | $mysqlDump = new MySQLDump($dest); | ||
| + | |||
| + | // Perform the backup | ||
| + | $mysqlDump-> | ||
| + | |||
| + | ?> | ||
| + | </ | ||
| + | |||
| + | test4.php: le fichier php à appeller en cgi, ne pas oublier de faire un chmod 755 test4.php | ||
| + | |||
| + | <code php> | ||
| + | #! / | ||
| + | <?php | ||
| + | /* | ||
| + | SCRIPT PERMETTANT DE CONVERTIR UNE TABLE MYSQL EN FICHIER XML SANS PRECISER LES CHAMPS | ||
| + | source: http:// | ||
| + | modified: | ||
| + | */ | ||
| + | |||
| + | // INFOS DE CONNEXION A LA BDD | ||
| + | |||
| + | $Sbddhost = ' | ||
| + | $Sbdduser = ' | ||
| + | $Sbddpass = ' | ||
| + | $Sbddbase = ' | ||
| + | $Sbdderreur = 'La base est inaccessible.'; | ||
| + | |||
| + | $Sbddtable = ' | ||
| + | |||
| + | $Sdatalimit = 0; // LIMIT DE DONNEES A CONVERTIR ( 0 = toutes ) | ||
| + | |||
| + | // DEFINIR L' | ||
| + | // LAISSER VIDE SI AUCUN ORDRE A DEFNIR | ||
| + | $dataorder = ''; | ||
| + | |||
| + | $filename = ' | ||
| + | |||
| + | $fileerreur = 'Le fichier ne peut être créé vérifier les droits du répertoire'; | ||
| + | |||
| + | // CONNEXION ET LECTURE TABLE | ||
| + | |||
| + | if(!$mysql_link = @mysql_connect($Sbddhost, | ||
| + | { | ||
| + | echo $Sbdderreur; | ||
| + | exit; | ||
| + | } | ||
| + | |||
| + | $sql = " | ||
| + | |||
| + | if(!empty($dataorder)) $sql .= " ORDER BY $dataorder"; | ||
| + | |||
| + | if($Sdatalimit >= 1) $sql .= " LIMIT $Sdatalimit"; | ||
| + | |||
| + | $req = mysql_query($sql, | ||
| + | $req2 = mysql_query($sql, | ||
| + | |||
| + | mysql_close($mysql_link); | ||
| + | |||
| + | // CONVERSION | ||
| + | |||
| + | $file = '<? | ||
| + | |||
| + | while($row = mysql_fetch_row($req)) { | ||
| + | |||
| + | $file .= '< | ||
| + | $i = 0; | ||
| + | foreach($row as $r){ | ||
| + | $r=trim($r); | ||
| + | $r=html_entity_decode($r); | ||
| + | $r=htmlspecialchars_decode($r); | ||
| + | $file .= '<##' | ||
| + | ++$i; | ||
| + | } | ||
| + | $file .= '</ | ||
| + | |||
| + | } | ||
| + | $file .= '</ | ||
| + | |||
| + | $i = 0; | ||
| + | while($field = mysql_fetch_field($req2)) { | ||
| + | $file = ereg_replace("## | ||
| + | ++$i; | ||
| + | } | ||
| + | |||
| + | // CREATION DU FICHIER | ||
| + | |||
| + | if($fp = @fopen($filename," | ||
| + | fputs($fp, | ||
| + | fclose($fp); | ||
| + | echo '<a href=' | ||
| + | }else{ echo $fileerreur; | ||
| + | |||
| + | |||
| + | ?> | ||
| + | </ | ||
| + | |||
| + | {{tag> | ||