I am trying to change the code in mysqli from mysql code using a single mysql_connect in a file that Is included in the second file.
mysql_connect provides a MySQL link identifier which is a super global so that you can rely on a database connection available in any of your tasks.
With this mysqli_connect it seems that this is not the case, the returned item is not global.
Does this mean I want to add: Global $ mysqli; At the top of each function, or is it a way to make a super global?
If you do not specify one, then PHP will use the Last Open Connection resource, maybe it's a Not very good idea.
What happens if your app changes and you need two connections or no connection?
It seems you need to do some refactoring anyway.
Here is a solution like Karsten that always gives the mysqli object.
class dB {private constant $ mysqli; Personal Function __construct () {} // An instantaneous static function cxn () {if (! Self :: $ mysqli) {self :: $ mysqli = new mysqli (...); } Return Self :: $ mysqli; }} // Usage DB :: CXN () - & gt; Ready (....
Comments
Post a Comment