更新PHP 7后phpMyImporterClass.php无法正常工作吗?

时间:2019-02-08 14:51:35

标签: php mysql restore

要恢复数据库mysql,我使用了此类“ phpMyImporterClass.php”,直到php 7更新为止。我认为mysql_select_db已过时,但我找不到如何修改它。我尝试通过mysqli_select_db更改mysql_select_db,但是没有结果。请你能帮我吗?

<?php
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;
        }
    }
}
?>

0 个答案:

没有答案
相关问题