Я могу разобрать CSV-файл и создать инструкции вставки на 100% правильно, когда CSV-файл доступен через URL-адрес. Проблема в том, что код не работает, когда я использую fopen
по адресу, заканчивающемуся ..format=csv
.Parsing PHP Issue - fopen() не работает правильно для CSV-файла
Есть ли что-нибудь, что мне не хватает в коде для того, чтобы это сработало?
<?php
$servername = "localhost";
$username = "root";
$password = "xxxx";
$dbname = "player";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
$f_pointer=fopen("URL-format=csv","r");
$sql = "TRUNCATE TABLE scores";
$conn->query($sql);
while(! feof($f_pointer)){
$ar=fgetcsv($f_pointer);
$sql="INSERT INTO scores(pos,errorthing,name,total)values('$ar[0]','$ar[1]','$ar[2]','$ar[3]','$ar[4]')";
$conn->query($sql);
echo $sql;
echo "<br>";
}
?>
Это сообщение об ошибке:
>[email protected]:/# php testing.php
PHP Notice: Undefined offset: 1 in /testing.php on line 21
PHP Notice: Undefined offset: 2 in /testing.php on line 21
PHP Notice: Undefined offset: 3 in /testing.php on line 21
PHP Notice: Undefined offset: 4 in /testing.php on line 21
INSERT INTO scores(pos,errorthing,name,total)values(??? UtUehOE_ZUzUAfAakQ87dsLbM.csvu??O????_a?t.????s??-??P?蜗+?L?r???ן??? Mj???g<?ӛ????_7??Q?D?Y?R?e?c','','','','')<br>PHP Notice: Undefined offset: 2 in /testing.php on line 21
PHP Notice: Undefined offset: 3 in /testing.php on line 21
PHP Notice: Undefined offset: 4 in /testing.php on line 21
INSERT INTO scores(pos,errorthing,name,total)values(' ??R?<???M??oCQ??0? P????[?*?q??EF?iB????','?EJsM???','','','')<br>PHP Notice: Undefined offset: 2 in /testing.php on line 21
PHP Notice: Undefined offset: 3 in /testing.php on line 21
PHP Notice: Undefined offset: 4 in /testing.php on line 21
4n c?%???o??'??q?wĠ!f1?)?d)ΐ??????z0?*total)values('R:
??','?g?ٓ4tG9????fd???*???','','','') <br>PHP Notice: Undefined offset: 4 in /testing.php on line 21
INSERT INTO scores(pos,errorthing,name,total)values('m?``???)??VZg?\{[email protected]?P?}???gY9y?p?TA=ˌ','[email protected]^Q?I~FR??%g??
*%;?M??.?&`??m?e cZy!????','4?xI??','#?????"}?.????u??d^????-e?dF?B','')<br>PHP Notice: Undefined offset: 3 in /testing.php on line 21
PHP Notice: Undefined offset: 4 in /testing.php on line 21
INSERT INTO scores(pos,errorthing,name,total)values('罡?m??7?&?ɣ
?g)??L3??l??T2?e[?v?
]!?????xm??ѧB?7?ļ?J?????ۋ?bA?»O?Y?4e?O??O?
cl??;???9-bZ?bط??Rk*t?????Ƣ??V??9??죨?\?۴ B??ԅ?T?a?OR? 3??P??????2~?}[email protected]?(????Ns%T1??i]=M???=?????+??)W#{Z?b?S)μ???W??','?3vK?qZ?D?7mE/T?
?ѡ????5?~SMl?bwɿ8J?ؾ>??1Q?/e?ifäs/U?D????'YI??m;NU?%ی?fx??٦?x#??Ù??_??_??O????e??{M???e?v?E??~?)????_??B??I??X?','','')<br>PHP Notice: Undefined offset: 1 in /testing.php on line 21
PHP Notice: Undefined offset: 2 in /testing.php on line 21
PHP Notice: Undefined offset: 3 in /testing.php on line 21
PHP Notice: Undefined offset: 4 in /testing.php on line 21
INSERT INTO scores(pos,errorthing,name,total)values('??w՛"???B???Ep?? DXҖ4:?Z?oU<?`???w??"?*?Ϛ???/??'7Ɂ?;q"?*?2?E?65??S4
^??"?<҃
pl??}?g?Ksw?'xI?x?R??8[??%d??? 0-kp??="D??r}J?־?g??','','','','')<br>PHP Notice: Undefined offset: 2 in /testing.php on line 21
PHP Notice: Undefined offset: 3 in /testing.php on line 21
PHP Notice: Undefined offset: 4 in /testing.php on line 21
INSERT INTO scores(pos,errorthing,name,total)values('v??Mrpqӳq????x??m??z?Z?ɮ??}R͘???3t?:\0YxOyLv8?ؠi?Mi??<?>?T?KN?<?j??.?ZB?','???c?R>???R??i????b?Ģ????Nb??b<V>鄪???(??$?ɓ(????L>??(????Ƿ'?."?t??q?f꼪?\????N?IH?ӡ?;?Y?iO4J??Xʤ9??Ă?5?RUb \V.?;?????2??QN????????+??MX???F?k?*h?Olr?Q$?&^9H?v}[email protected]?y?T?Ԯ???W?1?{??<???ܷN?b^V8
?T?????\?nv4l?j??}???(?','','','')<br>PHP Notice: Undefined offset: 2 in /testing.php on line 21
PHP Notice: Undefined offset: 3 in /testing.php on line 21
PHP Notice: Undefined offset: 4 in /testing.php on line 21
INSERT INTO scores(pos,errorthing,name,total)values('`??wp??g???????B? u?SS??x?a^hKhv???51?JԸ8S???5zQ6?숵?`ntn?C*VMk?ؔ~|????Pw?)?IF?g?|MCt?gS????"V ?KXf>?^?6?]???????xW?W???gێ!??d?QoH??]?!??ia??`ͨ?>?-?h?ki?K ƅ?? ?!ZQ???t??? O???`??3??u??P??c܁[email protected];????~?????8Gc?;?$sI?z??"??R5??N?;вX[?^? Aȃj??i??d','?[??0GUH?ٷ???c?*???Jl?V??a?j??lă?N:?&[email protected]?O?:? S??????mPY??v?a똺?????P?p?=?#???]???ow?????GPp','','','')<br>
Можете ли вы показать весь URL? –
Может быть, вычистить ошибку тоже немного - просто так, чтобы сообщество стало читать? – Fiid