My code is below.. using php to take data from SQL and post it using cURL. My question is after cURL encounters an error, is there a way to ignore it (or send it to a log file) and continue with the next line in the array? Currently as soon as it finds an error it's killing it.
<?php
// SQL connection stuff...
// fetch data from sql
$sql = "Select * from tablename";
$result = sqlsrv_query($conn, $sql) or die("Error in Selecting " . sqlsrv_error($conn));
// convert result to array
$array = array();
while($row = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC)) {
$array[] = $row;
}
foreach($array as $data) {
$post = http_build_query($data) . "\n";
//echo $post; //save this for testing later
}
// API url
$url = "www.example.com";
// initiate cURL
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_POST, true);
// execute POST
$response = curl_exec($ch);
// display errors
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
echo $status."=response"."</br>";
curl_close($ch);
// close connection
sqlsrv_close($conn)
?>