using an alias to a database name in a query

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
giles
Forum Commoner
Posts: 34
Joined: Thu Sep 14, 2006 2:34 pm

using an alias to a database name in a query

Post 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!
orlandinho
Forum Newbie
Posts: 18
Joined: Mon Feb 12, 2007 9:50 pm

Post 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' " ;
Post Reply