Пример #1
0
 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 = "&nbsp;";
                             }
                             $tab[$dummykey] = $col;
                         }
                         $result[] = $tab;
                     }
                 }
             }
         }
         return $result;
     } else {
         return array();
     }
 }
Пример #2
0
global $msg;
print "<table border=\"0\">";
print "<tr><td class=\"formtitle\">";
print "{$msg['529']}";
print "</td></tr><td>";
// initialisation
if (!empty($file)) {
    @set_time_limit(0);
    $dump_buffer = '';
    // 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);
Пример #3
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++;
     }
 }