doulachan8217 2015-10-30 00:15
浏览 9
已采纳

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

Fighting some lines of codes, that I copied because I didn't know how to write the fields from an object to MySQL. This used to work, but after changing the fields, the program now never come in the "If true" section anymore. When using printf($stmt) or print_r($stmt) in the false section, it returns an empty string.

Any help appreciated.

    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("
If 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("
%d Row inserted.
", $stmt->affected_rows);
    if(mysqli_stmt_errno($stmt) > 0)
    {
        printf("Error Nr.
", mysqli_stmt_errno($stmt));
        printf("Error  
",mysqli_stmt_error($stmt));
        $logRow = $logRow . "," . $stmt->affected_rows . "," . mysqli_stmt_error($stmt) . "
";
    }
    else
    {
        $logRow = $logRow . "," . $stmt->affected_rows . ",No Errors
";
    }
    $stmt->close();
 }
 else
 {
     printf("
If false");
     print_r($stmt);
     printf($stmt);
     printf("
End false");
 };

Any tips are welcome.

  • 写回答

1条回答 默认 最新

  • doudun5009 2015-10-30 00:34
    关注

    Copy these to lines into the bottom else statement, where you have your printf(" If false");

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

    This will tell you why the prepare fails. Then, based on that error, you can adapt. Likely an issue with column names in the database.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 用AT89C52单片机设计一个温度测量与控制电路
  • ¥15 无法import pycausal
  • ¥15 VS2022创建MVC framework提示:预安装的程序包具有对缺少的注册表值的引用
  • ¥15 weditor无法连接模拟器Local server not started, start with?
  • ¥20 6-3 String类定义
  • ¥15 嵌入式--定时器使用
  • ¥20 51单片机学习中的问题
  • ¥30 Windows Server 2016利用兩張網卡處理兩個不同網絡
  • ¥15 Python中knn问题
  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库