eelmitchell Posted March 27, 2009 Share Posted March 27, 2009 I have a function that does a SELECT statement but when it returns and I attempt to close the db resource I get the following message: Warning: mysqli_close() [function.mysqli-close]: Couldn't fetch mysqli in /homepages/13/d280102247/htdocs/GiftShop/salesform.php on line 45. I open the connection with mysqli_connect(...) The connect function assigns a value to $dbc. $dbc = mysqli_connect($server, $user, $password) or die('Error connecting to MySQL server.'); and then does a query to use my database. After that I invoke the function: // if the form asked to list the contents if(isset($_POST['list']) && ($_POST['list'] == 'List')) { ListSales(&$dbc); mysqli_close($dbc); Inside the function is a "SELECT * FROM sales" executed via an mysqli_query() statement. I tried passing the database resource variable $dbc by value and as above which I assume is by reference. Both syntax methods produce the same error message. The line 45 is the _close(...) statement. I don't know what the phrase "Couldn't fetch mysqli in ..." means in the error message. If I place the mysqli_close($dbc) within the function then I get no error message. I can only assume that the $dbc variable is carrying more info about the database than is visible to me and that any changes don't get transmitted outside the ListSales(...) function which would be reasonable if the $dbc were passed by value. Is there something I can do to stop the error message occurring? Quote Link to comment Share on other sites More sharing options...
corbin Posted March 27, 2009 Share Posted March 27, 2009 Resources are always passed by reference. I would assume that for some reason the link has already been closed. Quote Link to comment Share on other sites More sharing options...
eelmitchell Posted March 27, 2009 Author Share Posted March 27, 2009 I see now that msqli is a big class. When I tried to put together a simple test, there was a warning message: Call-time pass by reference has been deprecated. This is PHP 5.3. I got rid of the message by removing the mysqli_close, assuming that connection will be closed for me automatically. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.