Page 1 of 1

using an alias to a database name in a query

Posted: Tue Feb 13, 2007 8:22 pm
by giles
Hi all,

Is there any way that I can use something like define() to create an alias to a database name in a MySQL query? e.g. I currently have something like


Code: Select all

$result = mysql_query
    (
        "UPDATE DestDb 
        SET 
            answer = '$answer'
        WHERE session_id = '$session_id'
        AND count = '$count_history' "
    );


and it wold be great if I could do



Code: Select all

define("L_DestDb", "DestDb");


and subsequently use


Code: Select all

$result = mysql_query
    (
        "UPDATE L_DestDb 
        SET 
            answer = '$answer'
        WHERE session_id = '$session_id'
        AND count = '$count_history' "
    );


that way I can alter “DestDb” without having to trawl through my increasingly large project hunting out database instances!

Posted: Tue Feb 13, 2007 9:18 pm
by orlandinho
yo must use the alias taking it out of the string , something like this:

Code: Select all

$query="UPDATE " . L_DestDb . " SET answer = '$answer' WHERE session_id = '$session_id' AND count = '$count_history' " ;