Quote:
|
Originally Posted by big_k105
does this automaticly know the host is localhost? thats what im guessing but if say i was goin to run an application that uses this on a different server then the postgreSQL db then i would want to add a new var and 2 new functions called setHost and getHost thought i would double check to make sure 
|
Actually I just thought I'd tell you, he wouldn't need seperate member functions for that. The connection could automatically set localhost as the default connection if it's not specified. By setting $host or whatever as localhost at the member functions' definition point.
Actually this inspired me to write a PHP MySQL intergration class, here's a section of how to do that (for some weird reason vBulletin puts that weird space inbetween 'localhost'):[php] function cMySQL($username,$userpass,$db=FALSE,$host='localhost')
{
$this->cntlink = mysql_connect($host,$username,$userpass);
if($db != FALSE)
{
$this->currentdb; = mysql_select_db($db,$this->cntlink);
}
}
function selectDB($database)
{
$this->currentdb = mysql_select_db($database,$this->cntlink);
}[/php] Actually the member function cMySQL is the class constructor initiating the link. If no IP is passed, it assumes localhost is where the DB server is. You can also use that constructor to automatically select a database if you want and use the member selectDB to switch to another DB.
An example of this in action would be something like:[php]<?
require("cMySQL.php");
$cnt1 = new cMySQL("user","pass","db1","123.4.5.9");
//continue with code...
?>[/php]
Or, alternitavely:[php]<?
require("cMySQL.php");
$cnt1 = new cMySQL("user","pass");
//This will make the script assume the DB server is on localhost
$cnt1->selectDB("stuff");
?>[/php]
Just thought I'd inform you that you can do that to save yourself from making member functions that are ultimately pointless.
I thank my friends for showing me that trick.