4969 sujets

Sémantique web et HTML

Bonjour,
Cette Class qui me servait à restorer ma BDD ne fonctionne plus depuis la mise à jour de PHP7. je pensais trouver la solution en remplaçant le code mysql_select_db par mysqli_select_db, mais sans résultat.
Pouvez vous me dire s'il y a une solution pour continuer à utiliser cette class avec PHP 7 ?
Merci d'avance.


<?php
/**
* Class and Function List:
* Function list:
* - phpMyImporter()
* - setDatabase()
* - importSql()
* - doImport()
* Classes list:
* - phpMyImporter
*/
class phpMyImporter
{
    /**
     * @access private
     */
    var $database             = null;
    var $connection           = null;
    var $compress             = null;
    var $utf8                 = null;

    var $importFilename       = null;

    /**
     * Class constructor
     * @param string $db The database name
     * @param string $connection The database connection handler
     * @param boolean $compress It defines if the output/import file is compressed (gzip) or not
     * @param string $filepath The file where the dump will be written
     */
    function phpMyImporter($db                   = null, $connection           = null, $filepath, $compress             = false)
    {
        $this->connection     = $connection;
        $this->compress       = $compress;
        $this->importFilename = $filepath;

        $this->utf8           = true;

        return $this->setDatabase($db);
    }

    /**
     * Sets the database to work on
     * @param string $db The database name
     */
    function setDatabase($db)
    {
        $this->database = $db;
        if (!@mysql_select_db($this->database)) return false;
        return true;
    }

    /**
     * Read from SQL file and make sql query
     */
    function importSql($file)
    {
        // Reading SQL from file
        echo '
<div class = "container">
<div class="wrapper">
<div  class="form-signin">
<div align="center"><img src="img/download_60px.png" border="0" align="absmiddle" width="40px"/></div>
<h3 class="form-signin-heading">Restauration de la Base de Données</h3>
<hr class="colorgraph"><br>
<div align="center">';

        echo "Vérification du fichier : "; //$this->importFilename."': ";
        //echo "<br>";
        if ($this->compress)
        {
            $lines = gzfile($file);
        }
        else
        {
            $lines = file($file);
        }
        echo " OK!";
        echo "<br>";

        echo "Restauration des donn&eacute;es : "; //$this->database."':";
        //echo "<br>";
        $x         = 0;
        $importSql = "";
        $procent   = 0;
        foreach ($lines as $line)
        {
            // Print progress
            $x++;
            $numOfLines = count($lines);
            if ($x % (int)($numOfLines / 20) == 0)
            {
                $procent += 5;
                if ($procent % 25 == 0) echo "$procent% ";
                else echo "";
            }

            // Importing SQL
            $importSql .= $line;
            if (substr(trim($line) , strlen(trim($line)) - 1) == ";")
            {
                $query = @mysql_query($importSql, $this->connection);
                if (!$query) return false;
                $importSql = "";
            }
        }
        return true;
    }

    /**
     * Import SQL file into selected database
     */
    function doImport()
    {
        if (!$this->setDatabase($this->database)) return false;

        if ($this->utf8)
        {
            $encoding = @mysql_query("SET NAMES 'utf8'", $this->connection);
        }

        if ($this->importFilename)
        {
            $import   = $this->importSql($this->importFilename);
            if (!$import) echo "\n" . mysql_error($this->connection) . "\n";
            else echo '<div align="center"><img src="img/process_ok_60px.png" border="0" align="absmiddle" width="50px"/></div>';
            echo '<span style="color:green";>Restauration termin&eacute;e !</span>';
            echo '
</div>
</div>
</div>
</div>';
            return $import;
        }
        else
        {
            return false;
        }
    }
}
?>

Modifié par Canta (11 Feb 2019 - 17:25)