0

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?

3
  • How are you initializing your mysql connection ? maybe you didn't set it up correctly Commented May 26, 2016 at 8:33
  • Paste your full code!! Commented May 26, 2016 at 8:33
  • Show use the code of $this->conn->query Commented May 26, 2016 at 8:34

1 Answer 1

1

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!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.