Php 如何存储上载的.dat文件中的数据?
我有一个包含以下数据的文件“example.dat”Php 如何存储上载的.dat文件中的数据?,php,mysql,Php,Mysql,我有一个包含以下数据的文件“example.dat” 1 2018-09-06 16:29:18 1 2 2018-09-06 16:36:03 1 3 2018-09-06 16:36:11 1 4 2018-09-06 16:36:58 1 5 2018-09-06 16:37:56 1 6 2018-09-06 16:38:14 1 7 2018-09-06 16:43:
1 2018-09-06 16:29:18 1
2 2018-09-06 16:36:03 1
3 2018-09-06 16:36:11 1
4 2018-09-06 16:36:58 1
5 2018-09-06 16:37:56 1
6 2018-09-06 16:38:14 1
7 2018-09-06 16:43:53 1
我想将这些数据存储到mysql表“scheduler”中。我使用file_get_contents()读取内容,但如何将这些内容插入到具有sid、日期、时间和状态列的调度程序表中
if(!empty($_FILES)) {
$file = file_get_contents($_FILES["upload_cont_dat"]["tmp_name"], true);
// store content in table
}
我制作了一个小脚本,读取文件并解析每一行,然后获取所有数据。之后,我将其插入MySQL数据库
<?php
$handle = fopen("exmple.dat", "r");
if ($handle) {
$con = new mysqli($db_hostname, $db_username, $db_password, $db_databasename);
while (($line = fgets($handle)) !== false) {
// process the line read.
$line_exp = explode(" ", $line);
$sid = $line_exp[0];
$date = $line_exp[3];
$time = $line_exp[4];
$stat = $line_exp[5];
$stmt = $con->prepare("INSERT INTO `scheduler` (`sid`, `date`, `time`, `stat`) VALUES (?,?,?,?)");
$stmt->bind_param("ssss", $sid, $date, $time, $stat);
$stmt->execute();
}
$stmt->close();
fclose($handle);
} else {
// error opening the file.
}
使用INSERT查询?是使用INSERT抱歉回复太晚。这帮了大忙。没问题,很高兴能帮上忙