我复制了一些代码行,因为我不知道如何将对象中的字段写入MySQL。这曾经是有效的,但在更改字段后,该程序现在再也不会出现在"如果为真"部分。当在false部分中使用printf($stmt)或print_r($Stm)时,它会返回一个空字符串。
感谢您的帮助。
if ($stmt = $db->res->prepare("INSERT INTO rawdata( timestamp, NestName, NestUpdated, NestCurrentKelvin, "
. "NestTargetKelvin, NestTimeToTarget, NestHumidity, NestHeating, NestPostal_code, NestCountry, NestAutoAway, WeatherMain, "
. "WeatherDescription, WeatherTempKelvin, WeatherHumidity, WeatherTempMinKelvin, WeatherTempMaxKelvin, "
. "WeatherPressure, WeatherWindspeed, WeatherCityName) "
. "VALUES( ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"))
{
printf("nIf true");
$stmt->bind_param('sssiiiisssiissiiiiiis',
$NestData['timestamp'],
$NestData['NestName'],
$NestData['NestUpdated' ],
$NestData['NestCurrentKelvin'],
$NestData['NestTargetKelvin'],
$NestData['NestTimeToTarget'],
$NestData['NestHumidity'],
$NestData['NestHeating'],
$NestData['NestPostal_code'],
$NestData['NestCountry'],
$NestData['NestAutoAway'],
$NestData['NestManualAway'],
$NestData['WeatherMain'],
$NestData['WeatherDescription'],
$NestData['WeatherTempKelvin'],
$NestData['WeatherHumidity'],
$NestData['WeatherTempMinKelvin'],
$NestData['WeatherTempMinKelvin'],
$NestData['WeatherPressure'],
$NestData['WeatherWindspeed'],
$NestData['WeatherCityName']
);
$stmt->execute();
printf("n%d Row inserted.n", $stmt->affected_rows);
if(mysqli_stmt_errno($stmt) > 0)
{
printf("Error Nr.n", mysqli_stmt_errno($stmt));
printf("Error n",mysqli_stmt_error($stmt));
$logRow = $logRow . "," . $stmt->affected_rows . "," . mysqli_stmt_error($stmt) . "n";
}
else
{
$logRow = $logRow . "," . $stmt->affected_rows . ",No Errorsn";
}
$stmt->close();
}
else
{
printf("nIf false");
print_r($stmt);
printf($stmt);
printf("nEnd false");
};
欢迎任何提示。
将这些行复制到底部的else语句中,在那里您有printf("If false");
printf("Error Nr.n", mysqli_stmt_errno($stmt));
printf("Error n",mysqli_stmt_error($stmt));
这将告诉您准备失败的原因。然后,基于这个错误,你可以适应。数据库中的列名可能有问题。