Re: [PHP-PEAR] RFC on merge of PHPLib and Pear
[email protected] ((Kristian Koehntopp)) 10 Mar 2001 12:00:54 -0000
| Newsgroups | netuse.lists.php-pear |
|---|---|
| Message-ID | <[email protected]> |
In netuse.lists.php-pear you write:
>class. Could I use a config file without re-writing phplib's DB_sql, or setting
>the parameters manually after instantiating the object (ugly)? No.
$db = new DB_Sql; // constructor will terminate immediately
$db->Host = ...;
$db->User = ...;
$db->Password = ...;
$db->Database = ...;
$db->query(...); // query() will detect that there is no connect
// and will call connect() automatically.
The DB_Sql standard constructor does not take connection
parameters, but a query instead, because that is much more
useful and conventient in a real deployment scenario: In the
context of a single real world application, you have changing
queries, but your connection parameters change rarely.
Thus, being able to write by default
$db = new DB_mydatabase("select ..."); // connection parameters known implicitly by subclass
is much more useful as being to write
$db = new DB_Sql("localhost", "wwwrun", "secret", "test_test");
$db->query("...");
If you happen to have a scenario where you have need for the
latter, you could always subclass DB_Sql, overwrite the
constructor and use that derived class in the latter style.
Kristian