J. Hill wrote:
Reading the thread on mysqli connection issues, I am curious if anyone knows of a downside to creating a connection from a configuration page and using it as a global in all functions?

Good way to do it. You create the connection at the start and use the same thing throughout the whole script.

I am used to creating a class and a database handle for functions to use, but I inherited an intranet that just uses a single "$mysqli = mysqli_connect ...." in a global main file and the just uses "global $mysqli" in all of it's functions (several hundred) that interact with the database.

Since I have not seen this structure used elsewhere, I assume there is a good reason not to use it, but I haven't found one (except for the security issue in the use of globals).

Just "old style", nothing wrong with using it that way. The person who wrote it probably just didn't know about singletons. I can't see a security issue with it either.

$mysqli is set in the first file included (an 'init' type script).

As long as register_globals is off, it can't be overwritten by a $_GET or $_POST .. of course you can destroy it yourself, but that's it.

Postgresql & php tutorials

PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to