Jump to content

global connection to database


cliftonbazaar

Recommended Posts

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  :D )

Link to comment
https://forums.phpfreaks.com/topic/219019-global-connection-to-database/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.