Re: [PHP] More frustration with MySQL and PHP
- From: stuttle@xxxxxxxxx (Stut)
- Date: Tue, 22 Jan 2008 14:37:06 +0000
Jason Pruim wrote:
So all I have to do (At least to really simplify what I'm sure they can do) is put the code I want to execute into the function and then just list the variables as arguments? Such as:
function dbconnect ($host, $user, $pass, $database) {
mysqli_connect($host, $user, $pass, $database);
etc. etc.
}
Or something like that?
And then I can simply call my dbconnect() anywhere I might need to connect to a database? Or a different database?
Sort of. I believe the MySQLi extension is intelligent enough to not create multiple connections with the same details from one process, but you might find the following works a bit better...
http://dev.stut.net/php/db.inc.phps
This is modified from code I used to use but I have not tested this simplified version (the original supports multiple connections which you probably don't need). I now use a class instead of these functions but the basic idea is the same. At any point in your code you can simply to do...
$db = GetDB();
....to get a resource handle to your database, and it takes care of making sure it only keeps one connection around and closes it when the script ends.
Yes it uses globals. No I don't care.
-Stut
--
http://stut.net/
.
- References:
- More frustration with MySQL and PHP
- From: Jason Pruim
- Re: [PHP] More frustration with MySQL and PHP
- From: "Eric Butera"
- Re: [PHP] More frustration with MySQL and PHP
- From: Jason Pruim
- Re: [PHP] More frustration with MySQL and PHP
- From: Robert Cummings
- Re: [PHP] More frustration with MySQL and PHP
- From: Jason Pruim
- Re: [PHP] More frustration with MySQL and PHP
- From: Robert Cummings
- Re: [PHP] More frustration with MySQL and PHP
- From: "Dave Goodchild"
- Re: [PHP] More frustration with MySQL and PHP
- From: Jason Pruim
- More frustration with MySQL and PHP
- Prev by Date: Re: [PHP] More frustration with MySQL and PHP
- Next by Date: Re: [PHP] building php with DB extension without installing DB locally
- Previous by thread: Re: [PHP] More frustration with MySQL and PHP
- Next by thread: Re: [PHP] More frustration with MySQL and PHP
- Index(es):
Relevant Pages
|