1

我正在创建一个简单的 PHP 程序,它将多行数据存储到表中。但是当我运行程序时,它只填充了我试图填充的数千行中的一行。它也不给任何mysql_errors.

这是我的代码:

<?php
$tickets = explode(' ', file_get_contents("tickets.txt"));
foreach($tickets as &$ticket){
    $handle = opendir($ticket);
    while($file = readdir($handle)){
        if($file != "." && $file != ".."){
            $raw_data = file_get_contents($ticket."/".$file);
            $raw_data = trim(str_replace("Date,Open,High,Low,Close,Volume,Adj Close", "",          $raw_data));
            file_put_contents($ticket."/".$file, $raw_data);
            $file_temp = fopen($ticket."/".$file, "r");
            while(!feof($file_temp)){
                $line = fgets($file_temp);
                $data_array = explode(',', $line);
                $date = $data_array[0];
                $open = $data_array[1];
                $high = $data_array[2];
                $low = $data_array[3];
                $close = $data_array[4];
                $volume = $data_array[5];
                $adjclose = $data_array[6];
                $query = mysql_query("INSERT INTO `$ticket` VALUES  ('$date','$open','$high','$low','$close','$volume','$adjclose')");
                if(mysql_query("SELECT FROM $ticket WHERE `date`='$date'")){
                } else {
                    echo "ERROR";
                }
                echo $date.$open.$high.$low.$close.$volume.$adjclose."<br>";
                if(!$query){
                    mysql_error();
                }
            }
        }
    }
}
?>
4

0 回答 0