|
Posted by M. Trausch on 11/16/05 18:56
Gazornenplat wrote:
>
> DATABASE_CLASS is a constant
> DATABASE_CLASS(...) is a function which doesn't exist
>
*shrugs*. I was hoping that PHP's define() would work sort of something
along the lines of what the C preprocessor's #define does, so, while I
knew that, I didn't get the results that I'd quite expected. However,
see below...
>
> You could try something like:
>
> <?php
>
> define("DATABASE_CLASS", 'MySQL_5_Database("$user");');
> $user = "Ian";
>
> eval(DATABASE_CLASS);
>
> function MySQL_5_Database($user)
> {
> echo "Hello $user";
> }
> ?>
A slight adaptation to that made it work *perfectly*. I hadn't yet run
into eval(); (at least, before today). Thanks for the pointer! The way
I worked eval(); worked great, I just needed to know what it was that I
could do:
$dbClass = DATABASE_CLASS;
eval("\$db = new ${dbClass}(DATABASE_USER, DATABASE_PASS, DATABASE_NAME);");
(It's wrapped due to the e-mail client; not so in the actual code).
Thanks!
Mike
--
Strip the obvious trash from the header to send e-mail.
Navigation:
[Reply to this message]
|