1

insert is working in phpmyadmin but I can't figure out why it suddenly stopped working in my php code. The table itself has 2 columns, 1 is auto incremented the other is the value I attempt to insert. When the table hits 99760 entries inserts from the php script have no effect, however it's possible to insert values from phpmyadmin. The most recent summoner_id entered was 410893 and here is a link to an image of the table structure window: http://puu.sh/9KKuA/35cfcae788.png

<?php
$con=mysqli_connect("localhost", "root", "pass", "stats");

if (mysqli_connect_errno())
{
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$position = $_GET["count"];

$ids = strval($position);
for($i = $position + 1; $i < $position + 40; $i++)
{
    $ids = $ids . "," . strval($i);
}

do
{
    sleep(1);
    $raw = file_get_contents('https://euw.api.pvp.net/api/lol/euw/v1.4/summoner/' . $ids . '?api_key=****');
}while(strcmp($http_response_header[0], 'HTTP/1.1 429 429') == 0);

if(strcmp($http_response_header[0], 'HTTP/1.1 404 Not Found') == 0)
{
    return;
}

$data = json_decode($raw, true);

foreach($data as &$summoner)
{
    if($summoner["summonerLevel"] == 30)
    {
        $sql="INSERT INTO `active_summoners`(`summoner_id`) VALUES (" . $summoner["id"] . ")";

        if (!mysqli_query($con,$sql))
        {
            echo "Error: " . mysqli_error($con);
        }
    }
}
?>
5
  • Usually something like this fails when the summoner_id is a duplicate. You should get an error message about a unique key constraint violated - do you? Commented Jun 26, 2014 at 9:53
  • Not that I can tell? how can I check? Commented Jun 26, 2014 at 9:54
  • Are you sure the summoner_id field is an INT, you might have to put single quotes around it if its not.. ('".$summoner['id']."') Commented Jun 26, 2014 at 9:55
  • You can check by calling the script in a browser or look in /var/log/php5/error.log or /var/log/apache2/error.log Commented Jun 26, 2014 at 10:04
  • right I found the errors there but they aren't the source of the problem, I feel mildly retarded, as it turns out there is a huge gap in summoner id's (which is returned as a long by the api), the gap of no summoner id's is between 410907 and 18976513. Commented Jun 26, 2014 at 10:13

3 Answers 3

1

If you insert more records its will take more time. So we need to increase the execution time in the php file:

ini_set('max_execution_time', 3000);
Sign up to request clarification or add additional context in comments.

Comments

0

I think you should increase PHP execution size:

ini_set('max_execution_time', 0);

Then it will work fine.

Comments

0

Try the following code by putting it in top of the file:

set_time_limit(0);

Details.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.