Converting from mysql_ to mysqli_

I’ve figured out (I think) most of what I need to convert all of my 300k lines of code over to mysqli_ except one time…

With mysql_ I was able to (in the header) define a database connection and use it whenever needed as the page(s) loaded, including within functions, included scripts, etc. But, with mysqli_ it seems to not be persistent. I establish the connection in the same place I used to, giving it a variable of “$db” and it works fine within the page page being loaded. But I also include a general functions page, in which $db is undefined. Am I going to be forced to make a separate connection per external page being loaded or can I make this connection completely persistent? I’ve search and search and cannot come up with an answer to this.

Thank you.

If I’m am understanding you question I believe the fix would be to simply add global $db; to the your function. There might be another way of doing it, but this is the way I do it.

Sponsor our Newsletter | Privacy Policy | Terms of Service