I'm trying to make a script, in PHP, that reads from every txt file in a directory and writes the data to a MySQL database.
(我正在尝试用PHP创建一个脚本,该脚本从目录中的每个txt文件读取并将数据写入MySQL数据库。)
Right now the script runs on a local Wordpress environment however, nothing seems to happen when the script runs. (现在,脚本在本地Wordpress环境上运行,但是在脚本运行时似乎什么也没发生。)
I know there is a lot of bad variable names etc. in the code, it will be fixed once it's working. (我知道代码中有很多错误的变量名,等等,一旦工作就会解决。)
Thank you in advance! (先感谢您!)
function TxtToDB()
{
$directory = 'C:Usersuser-Local Sitesaxadevapppublicwp-contentuploadswp_dndcf7_uploadswpcf7-files';
$conn = mysqli_connect('localhost', 'root', 'root', 'mysql');
mysqli_connect();
if (!$conn) {
die(mysqli_error());
}
if (!is_dir($directory)) {
exit('Invalid diretory path');
}
$files = array();
foreach (scandir($directory) as $file) {
while (!feof($file)) {
$getTextLine = fgets($file);
$explodeLine = explode(",", $getTextLine);
list($a, $b, $c, $d, $e, $f, $g, $h, $i, $j, $k, $l, $m, $n, $o, $p, $q, $r, $s, $t, $u, $v, $w, $x, $y, $z, $de) = $explodeLine;
$qry = "insert into test_files (1,2,3,4) values('" . $a . "','" . $b . "','" . $c . "','" . $d . "')";
mysqli_query($conn, $qry);
}
fclose($file);
}
}
ask by Mico Boeje translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…