Re: Classes
| From: | Nicole Amashta | Date: | Thu, 14 Feb 2002 16:21:58 +0000 |
| Subject: | Re: Classes | ||
| References: | 1 | Groups: | php.windows |
| Request: | Send a blank email to php-windows+get-12087@lists.php.net to get a copy of this message | ||
I have a DB extraction class I wrote that supports both MySQL and MSSQL (and
can be easily extended to support others).
My class is also called DB.
<?
define( "MSSQL_DB", 1);
define( "MYSQL_DB",2);
class DB
{
var $db_type;
function DB($type)
{
$this->db_type = $type; ## the type of database connecting to: mssql or
mysql.
}
function connect($host,$un,$pw)
{ ##....
return $link
}
function select_db($dbname)
{
##....
return $dblink;
}
## ...
} // end class DB
?>
To instantiate a class, you have to use "new"
$db = new DB(MSSQL_DB); #
$link = $db->connect($host,$un,$pw);
$dblink = $db->select_db($dbname);
The syntax below:
> $conn = DB::Connect($connstr);
> $conn->query($sql);
Is that it? Because maybe that is a form of using the class statically (??
reminds me of Java).
"Brian Feliciano" <brian@websensegroup.com> wrote in message
news:200202141725.g1EHPrb13874@www.virtuaservers.com...
> i've seen a code like this...
> -----------
> $conn = DB::Connect($connstr);
> $conn->query($sql);
> -----------
> i think this is from PEAR's DB abstraction layer..
> but my problem is, i don't know how to create a class
> like the 'DB'. I tried to, but i failed.
>
> How can i create an instance of a class without using
> "new" ?
>
>
>
>
>
>
> --
> =============================
> B r i a n F e l i c i a n o
> =============================
> Server Administrator
> The Websense Group Co.
> -----------------------------
> Unit 103 Terris Villa Sikap St.
> Mandaluyong City, Philippines
> Tel. No.: (632) 7462449
> Fax. No.: (632) 7462482
> Mobile Phone No.: +639176189153