0
I’m trying to file a requisition cURL
for each line returned by a query in a database. The problem is that my program dies right after the first call cURL
, and I have no idea why.
Searching the internet, I saw that the ideal would be to separate the call cURL
in a function outside the while, but that did nothing. Simplifying a lot of my code, that’s what I have so far:
<?php
include_once('config.php');
ini_set('max_execution_time', 0);
header('Content-Type: application/json');
$stmt = $connection->prepare("SELECT * FROM tabela");
$array = array();
if($stmt->execute()) {
while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$retorno = callCurl($row["info"]);
$sql = "UPDATE tabela SET coluna1 = ?, coluna2 = ? WHERE id = ?";
$stmt = $connection->prepare($sql);
$stmt->execute(array($retorno["lat"], $retorno["lng"], $row["id"]));
array_push($array, $retorno);
}
}
echo json_encode($array);
function callCurl($info) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'meulink.com.br/script.php?param=' . $info);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$retorno = json_decode(curl_exec($ch), TRUE);
curl_close($ch);
return $retorno;
}
?>
My suspicion is that the curl_init
is breaking in the second while iteration, but I have no idea why. Even trying to use curl_error
nothing is returned, the program only dies.
Already checked the server error log file?
– Woss
The error was not in the Curl, but in the only thing left to test: the
UPDATE
, Derp.– Daniel Bertoldi