dongyue8640 2013-11-03 12:43
浏览 28

如何添加选择按钮上传.sql文件

how can i add chose button to select .sql file and upload data to mysql

this is chose button code

<!DOCTYPE html>
<html>
<body>

<form action="upload.php">
  Select a file: <input type="file" name="img">
  <input type="submit">
</form>

</body>
</html>

and this is upload .sql file code is working perfect but i want to add chose button to upload .sql file to mysql how can i add chose button please help me

<?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";
?>
  • 写回答

1条回答 默认 最新

  • dounai7148 2013-11-03 12:47
    关注

    Use the exec() and the command

    mysql -u username -p -h localhost DATA-BASE-NAME < your-dump-file.sql 
    

    To import a mysql dump file. It's a lot easier and more bullet proofed than to write an own mysql dump file parser.

    Or to access your img form field in your PHP script use the $_FILES['img'] variable. It contains all the information about the uploaded file. And add to your form tag the attribute enctype="multipart/form-data" that your file gets uploaded to the server.

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度