function mysqlTable($action) { global $pmb_set_time_limit, $dbh; if (SESSrights & ADMINISTRATION_AUTH) { $result = array(); if ($action) { @set_time_limit($pmb_set_time_limit); $db = DATA_BASE; $tables = pmb_mysql_list_tables($db); $num_tables = @pmb_mysql_num_rows($tables); $i = 0; while ($i < $num_tables) { $table[$i] = pmb_mysql_tablename($tables, $i); $i++; } while (list($cle, $valeur) = each($table)) { $requete = $action . " TABLE " . $valeur . " "; $res = @pmb_mysql_query($requete, $dbh); $nbr_lignes = @pmb_mysql_num_rows($res); if ($nbr_lignes) { for ($i = 0; $i < $nbr_lignes; $i++) { $row = pmb_mysql_fetch_row($res); $tab = array(); foreach ($row as $dummykey => $col) { if (!$col) { $col = " "; } $tab[$dummykey] = $col; } $result[] = $tab; } } } } return $result; } else { return array(); } }
// définition du retour chariot $crlf = "\n"; $db = "bibli"; $today = date("d/m/Y H:i:s"); $separator = "# ------------------------------------{$crlf}"; // construction du dump $tables = pmb_mysql_list_tables($db); $num_tables = @pmb_mysql_num_rows($tables); // en-tête $dump_buffer .= "{$separator}# pmb MySQL-Dump{$crlf}"; $dump_buffer .= "# {$today}{$crlf}"; $dump_buffer .= "# backup base \"{$db}\"{$crlf}"; $dump_buffer .= $separator . $crlf; $i = 0; while ($i < pmb_mysql_num_rows($tables)) { $table[$i] = pmb_mysql_tablename($tables, $i); $i++; } while (list($cle, $valeur) = each($table)) { $requete = "SHOW CREATE TABLE {$valeur}"; $result = pmb_mysql_query($requete, $dbh); $create = pmb_mysql_fetch_row($result); // écriture de la méthode de création $dump_buffer .= "{$crlf}{$separator}# structure de la table {$valeur}{$crlf}{$separator}{$crlf}"; $dump_buffer .= "DROP TABLE IF EXISTS " . $valeur . ";{$crlf}"; $dump_buffer .= $create[1] . ";{$crlf}"; $dump_buffer .= "{$crlf}{$separator}# contenu de la table {$valeur}{$crlf}{$separator}{$crlf}"; // écriture des données $requete = "SELECT * FROM {$valeur}"; $result = pmb_mysql_query($requete, $dbh); $nbr_lignes = pmb_mysql_num_rows($result);
<?php // +-------------------------------------------------+ // © 2002-2004 PMB Services / www.sigb.net pmb@sigb.net et contributeurs (voir www.sigb.net) // +-------------------------------------------------+ // $Id: tables.inc.php,v 1.11 2015-04-03 11:16:24 jpermanne Exp $ if (stristr($_SERVER['REQUEST_URI'], ".inc.php")) { die("no access"); } // on récupére la liste des tables $result = pmb_mysql_query("SHOW TABLES FROM " . DATA_BASE); $i = 0; while ($i < pmb_mysql_num_rows($result)) { $table[$i] = pmb_mysql_tablename($result, $i); $desc[$i] = "<table >"; $desc[$i] .= "<tr><th><strong>Field</strong></th><th><strong>Type</strong></th><th><strong>Null</strong></th><th><strong>Key</strong></th><th><strong>Default</strong></th><th><strong>Extra</strong></th></tr>"; $requete = "DESCRIBE {$table[$i]}"; $res = pmb_mysql_query($requete, $dbh); $nbr = pmb_mysql_num_rows($res); if ($nbr) { $odd_even = 1; for ($j = 0; $j < $nbr; $j++) { $row = pmb_mysql_fetch_row($res); if ($odd_even == 0) { $pair_impair = "odd"; $odd_even = 1; } else { if ($odd_even == 1) { $pair_impair = "even"; $odd_even = 0; }
function fetch_data() { global $dbh; //enumerate tables $res = pmb_mysql_list_tables(DATA_BASE); $i = 0; while ($i < pmb_mysql_num_rows($res)) { $update_a_faire = 0; /* permet de gérer les id auto_increment qui auraient pour valeur 0 */ $table_name = pmb_mysql_tablename($res, $i); bzwrite($this->fptr, "delete from {$table_name};\n"); $this->dump .= "delete from {$table_name};\n"; //parse the field info first $res2 = pmb_mysql_query("select * from {$table_name} order by 1 ", $dbh); $nf = pmb_mysql_num_fields($res2); $nr = pmb_mysql_num_rows($res2); $fields = ''; $values = ''; for ($b = 0; $b < $nf; $b++) { $fn = pmb_mysql_field_name($res2, $b); $ft = pmb_mysql_field_type($res2, $b); $fs = pmb_mysql_field_len($res2, $b); $ff = pmb_mysql_field_flags($res2, $b); $is_numeric = false; switch (strtolower($ft)) { case "int": $is_numeric = true; break; case "blob": $is_numeric = false; break; case "real": $is_numeric = true; break; case "string": $is_numeric = false; break; case "unknown": switch (intval($fs)) { case 4: // little weakness here... // there is no way (thru the PHP/MySQL interface) // to tell the difference between a tinyint and a year field type $is_numeric = true; break; default: $is_numeric = true; break; } break; case "timestamp": $is_numeric = true; break; case "date": $is_numeric = false; break; case "datetime": $is_numeric = false; break; case "time": $is_numeric = false; break; default: //future support for field types that are not recognized //(hopefully this will work without need for future modification) $is_numeric = true; //I'm assuming new field types will follow SQL numeric syntax.. // this is where this support will breakdown break; } $fields ? $fields .= ', ' . $fn : ($fields .= $fn); $fna[$b] = $fn; $ina[$b] = $is_numeric; } //parse out the table's data and generate the SQL INSERT statements in order to replicate the data itself... for ($c = 0; $c < $nr; $c++) { $row = pmb_mysql_fetch_row($res2); $values = ''; for ($d = 0; $d < $nf; $d++) { $data = strval($row[$d]); if ($d == 0 && strval($row[$d]) == 0) { /* traiter ici l'insertion avec valeur 1 pour id autoincrement et update à suivre */ $values ? $values .= ', ' . '1' : ($values .= '1'); $cle_update = pmb_mysql_field_name($res2, 0); $update_a_faire = 1; } else { if ($ina[$d] == true) { $values ? $values .= ', ' . intval($data) : ($values .= intval($data)); } else { $values ? $values .= ", \"" . pmb_mysql_escape_string($data) . "\"" : ($values .= "\"" . pmb_mysql_escape_string($data) . "\""); } } } bzwrite($this->fptr, "insert into {$table_name} ({$fields}) values ({$values});\n"); $this->dump .= "insert into {$table_name} ({$fields}) values ({$values});\n"; if ($update_a_faire == 1) { $update_a_faire = 0; bzwrite($this->fptr, "update {$table_name} set " . $cle_update . "='0' where " . $cle_update . "='1';\n"); $this->dump .= "update {$table_name} set " . $cle_update . "='0' where " . $cle_update . "='1';\n"; } } pmb_mysql_free_result($res2); $i++; } }