mysql - Parsing PHP Issue - fopen() not working correctly for CSV File -


i can parse csv file , create insert statements 100% correct when csv file accessible via url. issue code not work when use use fopen on url ending in ..format=csv.

is there missing in code work?

<?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     scores(pos,errorthing,name,total)values('$ar[0]','$ar[1]','$ar[2]','$ar[3]','$ar[4]')"; $conn->query($sql);    echo $sql;  echo "<br>";     }  ?> 

this error message:

>root@morryserver:/# 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 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 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 scores(pos,errorthing,name,total)values('m?``???)??vzg?\{???@?p?}???gy9y?p?ta=ˌ','????@^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 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~?}?f?8??c??lk@?(????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 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 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}k?f??8@g?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 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܁?r?g???e?b3????@;????~?????8gc?;?$si?z??"??r5??n?;вx[?^?    aȃj??i??d','?[??0guh?ٷ???c?*???jl?v??a?j??lă?n:?&z?nl???m??=t??@w?o?:?    s??????mpy??v?a똺?????p?p?=?#???]???ow?????gpp','','','')<br> 

in code not getting values $ar[0],$ar[1],$ar[2] etc, so, getting errors.

try this, know, how open .csv file, read contents , inserting respective columns of database.

   $row = 1;    if (($handle = fopen("xxxxxxxxx.csv", "r")) !== false) {    while (($data = fgetcsv($handle, 1000, ",")) !== false) {     $num = count($data);     echo "<p> $num fields in line $row: <br /></p>\n";        $row++;     ($c=0; $c < $num; $c++) {         $blackpowder = $data;         $dynamit = implode(";", $blackpowder);         $pieces = explode(";", $dynamit);         $col1 = $pieces[0];         $col2 = $pieces[1];         $col3 = $pieces[2];         $col4 = $pieces[3];         $col5 = $pieces[5];         mysql_query("             insert `xxxxxx`                  (`xxx`,`xxx`,`xxx`,`xxxx`,`xxx`)              values                  ('".$col1."','".$col2."','".$col3."','".$col4."','".$col5."')         ");     } } } 

Comments