我复制了一些代码,因为我不知道如何将字段从对象写入MySQL。以前可以使用,但是更改字段后,该程序现在不再位于“ If true”部分。在false部分中使用printf($ stmt)或print_r($ stmt)时,它将返回一个空字符串。

任何帮助表示赞赏。

    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 Errors\n";
    }
    $stmt->close();
 }
 else
 {
     printf("\nIf false");
     print_r($stmt);
     printf($stmt);
     printf("\nEnd false");
 };


欢迎任何提示。

最佳答案

将这些行复制到底部的else语句中,在这里您有printf(“ \ nIf false”);

printf("Error Nr.\n", mysqli_stmt_errno($stmt));
printf("Error  \n",mysqli_stmt_error($stmt));


这将告诉您准备失败的原因。然后,根据该错误,您可以进行调整。数据库中的列名可能有问题。

关于php - $ db-> res->准备不再工作,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33426922/

10-09 01:44