第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何使用php在mysql數(shù)據(jù)庫(kù)中導(dǎo)入.sql文件

如何使用php在mysql數(shù)據(jù)庫(kù)中導(dǎo)入.sql文件

梵蒂岡之花 2019-11-22 15:20:59
如何使用php在mysql數(shù)據(jù)庫(kù)中導(dǎo)入.sql文件我該怎么辦,請(qǐng)幫助我解決此問(wèn)題,謝謝此代碼顯示此錯(cuò)誤。There was an error during import. Please make sure the import file is saved in the same folder as this script and check your values:MySQL Database Name:    testMySQL User Name:    rootMySQL Password: NOTSHOWNMySQL Host Name:    localhostMySQL Import Filename:  dbbackupmember.sql我正在使用此代碼<?php//ENTER THE RELEVANT INFO BELOW$mysqlDatabaseName ='test';$mysqlUserName ='root';$mysqlPassword ='';$mysqlHostName ='localhost';$mysqlImportFilename ='dbbackupmember.sql';//DONT EDIT BELOW THIS LINE//Export the database and output the status to the page$command='mysql -h' .$mysqlHostName .' -u' .$mysqlUserName .' -p' .$mysqlPassword .' ' .$mysqlDatabaseName .' < ' .$mysqlImportFilename;exec($command,$output=array(),$worked);switch($worked){    case 0:        echo 'Import file <b>' .$mysqlImportFilename .'</b> successfully imported to database <b>' .$mysqlDatabaseName .'</b>';        break;    case 1:        echo 'There was an error during import. Please make sure the import file is saved in the same folder as this script and check your values:<br/><br/><table><tr><td>MySQL Database Name:</td><td><b>' .$mysqlDatabaseName .'</b></td></tr><tr><td>MySQL User Name:</td><td><b>' .$mysqlUserName .'</b></td></tr><tr><td>MySQL Password:</td><td><b>NOTSHOWN</b></td></tr><tr><td>MySQL Host Name:</td><td><b>' .$mysqlHostName .'</b></td></tr><tr><td>MySQL Import Filename:</td><td><b>' .$mysqlImportFilename .'</b></td></tr></table>';        break;}?>
查看完整描述

3 回答

?
HUWWW

TA貢獻(xiàn)1874條經(jīng)驗(yàn) 獲得超12個(gè)贊

我還有另一種方法可以嘗試


<?php


// Name of the file

$filename = 'churc.sql';

// MySQL host

$mysql_host = 'localhost';

// MySQL username

$mysql_username = 'root';

// MySQL password

$mysql_password = '';

// Database name

$mysql_database = 'dump';


// Connect to MySQL server

mysql_connect($mysql_host, $mysql_username, $mysql_password) or die('Error connecting to MySQL server: ' . mysql_error());

// Select database

mysql_select_db($mysql_database) or die('Error selecting MySQL database: ' . mysql_error());


// Temporary variable, used to store current query

$templine = '';

// Read in entire file

$lines = file($filename);

// Loop through each line

foreach ($lines as $line)

{

// Skip it if it's a comment

if (substr($line, 0, 2) == '--' || $line == '')

    continue;


// Add this line to the current segment

$templine .= $line;

// If it has a semicolon at the end, it's the end of the query

if (substr(trim($line), -1, 1) == ';')

{

    // Perform the query

    mysql_query($templine) or print('Error performing query \'<strong>' . $templine . '\': ' . mysql_error() . '<br /><br />');

    // Reset temp variable to empty

    $templine = '';

}

}

 echo "Tables imported successfully";

?>

這對(duì)我有用,祝你好運(yùn)


查看完整回答
反對(duì) 回復(fù) 2019-11-22
?
慕沐林林

TA貢獻(xiàn)2016條經(jīng)驗(yàn) 獲得超9個(gè)贊

Raj的答案很有用,但是(由于file($ filename))如果您的mysql-dump不適合內(nèi)存,它將失敗


如果您在共享主機(jī)上,并且有30 MB和12s腳本運(yùn)行時(shí)之類(lèi)的限制,并且必須還原x00MB mysql dump,則可以使用以下腳本:


它將在轉(zhuǎn)儲(chǔ)文件查詢(xún)中進(jìn)行查詢(xún),如果腳本執(zhí)行截止日期臨近,它將當(dāng)前文件位置保存在tmp文件中,并且自動(dòng)重新加載瀏覽器將一次又一次地繼續(xù)此過(guò)程...如果發(fā)生錯(cuò)誤,則重新加載將停止并顯示錯(cuò)誤...


如果您從午餐回來(lái),您的數(shù)據(jù)庫(kù)將恢復(fù);-)


noLimitDumpRestore.php:


// your config

$filename = 'yourGigaByteDump.sql';

$dbHost = 'localhost';

$dbUser = 'user';

$dbPass = '__pass__';

$dbName = 'dbname';

$maxRuntime = 8; // less then your max script execution limit



$deadline = time()+$maxRuntime; 

$progressFilename = $filename.'_filepointer'; // tmp file for progress

$errorFilename = $filename.'_error'; // tmp file for erro


mysql_connect($dbHost, $dbUser, $dbPass) OR die('connecting to host: '.$dbHost.' failed: '.mysql_error());

mysql_select_db($dbName) OR die('select db: '.$dbName.' failed: '.mysql_error());


($fp = fopen($filename, 'r')) OR die('failed to open file:'.$filename);


// check for previous error

if( file_exists($errorFilename) ){

    die('<pre> previous error: '.file_get_contents($errorFilename));

}


// activate automatic reload in browser

echo '<html><head> <meta http-equiv="refresh" content="'.($maxRuntime+2).'"><pre>';


// go to previous file position

$filePosition = 0;

if( file_exists($progressFilename) ){

    $filePosition = file_get_contents($progressFilename);

    fseek($fp, $filePosition);

}


$queryCount = 0;

$query = '';

while( $deadline>time() AND ($line=fgets($fp, 1024000)) ){

    if(substr($line,0,2)=='--' OR trim($line)=='' ){

        continue;

    }


    $query .= $line;

    if( substr(trim($query),-1)==';' ){

        if( !mysql_query($query) ){

            $error = 'Error performing query \'<strong>' . $query . '\': ' . mysql_error();

            file_put_contents($errorFilename, $error."\n");

            exit;

        }

        $query = '';

        file_put_contents($progressFilename, ftell($fp)); // save the current file position for 

        $queryCount++;

    }

}


if( feof($fp) ){

    echo 'dump successfully restored!';

}else{

    echo ftell($fp).'/'.filesize($filename).' '.(round(ftell($fp)/filesize($filename), 2)*100).'%'."\n";

    echo $queryCount.' queries processed! please reload or wait for automatic browser refresh!';


查看完整回答
反對(duì) 回復(fù) 2019-11-22
?
慕哥6287543

TA貢獻(xiàn)1831條經(jīng)驗(yàn) 獲得超10個(gè)贊

您可以使用mysqli multi_query函數(shù),如下所示:


$sql = file_get_contents('mysqldump.sql');


$mysqli = new mysqli("localhost", "root", "pass", "testdb");

if (mysqli_connect_errno()) { /* check connection */

    printf("Connect failed: %s\n", mysqli_connect_error());

    exit();

}


/* execute multi query */

if ($mysqli->multi_query($sql)) {

    echo "success";

} else {

   echo "error";

}


查看完整回答
反對(duì) 回復(fù) 2019-11-22
  • 3 回答
  • 0 關(guān)注
  • 1144 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)