Jump to content
PHPremote

dbconnect error? "Couldn't fetch mysqli" error when same query works elsewhere

Recommended Posts

My code here works in some locations but not others. I believe it may be due to a faulty database connection. The $dbconnection gets returned from a function intended for the purpose and then passed to functions as needed.

I am getting this error message for a $conn->query("SELECT * FROM formstable"); :

Quote

Warning: mysqli::query(): Couldn't fetch mysqli in C:\xampp\htdocs\ ...

(The warning goes on to specify the page and line number of course.)

The code works within the database connection function just before my "return $conn;" statement.

It works within a function "askQuery" called from one location but not anorher.

It does not work at all in a function "showSelect".

 

This seems the most relevant code:
 

    $newsqlStatement = showSelect($testConn, "SELECT * FROM formstable"); // will later isolate selectStatement WHERE formname = formname

function showSelect($conn, $sqlStatement) {

            $result = $conn->query("SELECT * FROM formstable");

.

'

'

    return $successSelect; // for now just true or false
} // end function showSelect

 

 

Edited by PHPremote

Share this post


Link to post
Share on other sites

The function is defined in a file brought in via "include" . The call is in the main file.

 

My intent is to search for a prepared MySQL search term corresponding to the form submitted, and any other corresponding queries like an insert.

Share this post


Link to post
Share on other sites

It works now. I had called $conn->close(); immediately after establishing it. It was to deal with an earlier error, although I do not remember what. :(

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...