Jump to content

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


PHPremote
 Share

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
Link to comment
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.

Link to comment
Share on other sites

  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...