$ db-> res->准备不再工作

时间:2015-10-30 00:15:15

标签: php mysql

战斗一些代码行,我复制了,因为我不知道如何将对象中的字段写入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");
 };

欢迎任何提示。

1 个答案:

答案 0 :(得分:0)

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

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

这将告诉您准备失败的原因。然后,根据该错误,您可以适应。可能是数据库中列名称的问题。