dongnan1989 2016-05-26 08:30
浏览 55
已采纳

PHP mysql错误,无法INSERT到数据库

I have these lines of PHP code:

$sql2 = "INSERT INTO TableName ... " //an example, line is very long
error_log($sql2);
$result2 = $this->conn->query($sql2); //line 81

I get this error in PHP error log:

PHP Warning:  mysqli::query(): Couldn't fetch mysqli in /volume1/web/DB_Functions.php on line 81

My first idea was that my $sql2 string is not valid, but when I copied it from PHP error log and pasted it to PhpMyAdmin as SQL it works pretty well, what could be wrong?

  • 写回答

1条回答 默认 最新

  • dsajdgjadwqe3247382 2016-05-26 08:46
    关注

    I think it is because when you close the database connection the first time, you forget to do:

    unset($this->conn);
    

    And then when you try connecting to the database again, it craps out because it is still set to the closed connection. Originally referenced from: Warning: mysqli_query(): Couldn't fetch mysqli

    Hope it solve your problem!

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

报告相同问题?

悬赏问题

  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程