I have this code, it only inserts the first $listing, then the others are ignored, mysqli_query doesnot return any errors, I was having a issue with column being truncated, but I fix that issue,
When I copy and paste the $sql1 on phpmyadmin, it works with no issues.
$resource = "Property";
$classArray = array("RES");
foreach ($classArray as $pClass){
//$maxRows = true;
//$offset = 1;
//$limit = 9999999;
//while($maxRows){
//$results = $rets->Search($resource, $pClass, $query);
$results = $rets->Search($resource, $pClass, 'ModificationTimestamp=2018-04-25T00:00:00+'); //, [
//'Limit' => $limit,
//'Format' => 'COMPACT-DECODED',
//'Select' => $selectFields,
//'Offset' => $offset
//]);
//$count = 0;
$results->toArray();
foreach($results as $listing){
//GENERATE TABLE NAME
$table_name = "rets_".strtolower($resource)."_".strtolower($pClass);
/// Truncate Table to perform fresh import.
$truncateSQL = "TRUNCATE TABLE ".$table_name;
if(!mysqli_query($link, $truncateSQL)){
echo "Failed to Truncate Table<br/>";
die();
}
//PREPARE DATA TO GO IN DATABASE
$fields = $listing->toArray();
//$values = array();
$fieldValues='';
$fieldNames='';
$oldDate = 'DEFAULT';//date("Y-m-d",strtotime("2001-08-06"));
foreach($fields as $field => $value){
//echo "Key=" . $field . ", Value=" . $value."<br/>";
if($field == "ExpectedOnMarketDate"){
$value = $oldDate;
}elseif(is_numeric($value)){
$value = $value;
}elseif(empty($value)){
$value = 'DEFAULT';
}else{
$value = "'".mysqli_real_escape_string($link, $value)."'";
//$value = $value;
}
$fieldValues.= $value.',';
$fieldNames.= $field.',';
unset($field);
unset($value);
}
$fieldValues = rtrim($fieldValues, ',');
$fieldNames = rtrim($fieldNames, ',');
$sql1 = "INSERT INTO ".$table_name." ($fieldNames) VALUES ($fieldValues)";
echo "<hr/>";
//echo str_replace(",", "<br/>", $fieldNames)."<br/>";
//echo str_replace(",", "<br/>", $fieldValues)."<br/>";
echo $sql1;
if (mysqli_query($link, $sql1)) {
echo "Record Created for: " . $listing['ListingID'] . "\r\n <br/>";
}else{
echo "ERROR: " . mysqli_error($link) . "\r\n\r\n <br/>";
}
//$count++;
unset($fieldNames);
unset($fieldValues);
unset($listing);
unset($sql1);
}
//$offset = ($offset + $count);
//$maxRows = $results->IsMaxrowsReached();
// }
echo "Done Getting Listings from server.<br/>";
die();
}
Thank you for your time.