I'm getting this error when parsing data from a URL using fgetcsv() in php.
Here's my Error: PHP Warning: fgetcsv() expects parameter 1 to be resource, boolean given in /testing.php on line 20
Note: I have tired a possible solution with no luck PHP return error when using fgetcsv
Dataset: What I'm trying to parse with fgetcsv()
{"pos":[{"pos":"1","person":"John","place":"8","score":"109","round":"1"}, {"pos":"2","person":"Mary","score":"80"},{"pos":"3","person":"Luke Guthrie","place":"7*","score":"7","round":"1"}, {"pos":"4","person":"Charles","score":"3"},{"pos":"5","person":"Sean","place":"8","score":"4","round":"1"}, {"pos":"6","person":"Rob","score":"60"}, {"pos":"7","person":"Dan","score":"76"},{…
Here's my php file:
<?php
$servername = "localhost";
$username = "root";
$password = "xxxx";
$dbname = "player";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
$f_pointer=fopen("URL/api/v2/projects/xxx/last_ready_run/data","r");
while(! feof($f_pointer))
{
$ar=fgetcsv($f_pointer);
$sql="INSERT INTO scores(pos,person,score,place,score,round)values('$ar[0]','$ar[1]','$ar[2]','$ar[3]','$ar[4]','$ar[5]')";
$conn->query($sql);
echo $sql;
echo "<br>";
}
?>
Try again with some error handling.
$f_pointer=fopen("URL/api/v2/projects/xxx/last_ready_run/data","r");
if ( !$f_pointer ) {
trigger_error('fopen failed', E_USER_ERROR);
}
Anyway fgetcsv() is not the right function to parse json. json_decode() is.