cliftonbazaar Posted November 17, 2010 Share Posted November 17, 2010 Through out my program I have used global $mysqli; as a connection to my database - this has worked fine so far. Now I have called $sql_statement = "SELECT * FROM items WHERE name='$itemName'"; $itemStats = mysqli_fetch_array(mysqli_query($mysqli, $sql_statement), MYSQLI_ASSOC); via a function and I get the following warnings - Warning: mysqli_query() expects parameter 1 to be mysqli, null given in /functions/getdata.php on line 27 Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in /functions/getdata.php on line 27 it still works though and returns the correct information. If I take the code out of the function and use it normally then I get no Warnings - but this defeats the whole purpose of having functions! How do I get rid of the warnings? (and no, I don't mean turn the warnings off ) Quote Link to comment https://forums.phpfreaks.com/topic/219019-global-connection-to-database/ Share on other sites More sharing options...
trq Posted November 18, 2010 Share Posted November 18, 2010 but this defeats the whole purpose of having functions! So does using globals. You need to pass your connection to any functions that need it via an argument. Quote Link to comment https://forums.phpfreaks.com/topic/219019-global-connection-to-database/#findComment-1135844 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.