_giles_ Posted February 14, 2007 Share Posted February 14, 2007 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 $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 define("L_DestDb", "DestDb"); and subsequently use $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! Quote Link to comment https://forums.phpfreaks.com/topic/38413-solved-using-an-alias-to-a-database-name-in-a-query/ Share on other sites More sharing options...
benjaminbeazy Posted February 14, 2007 Share Posted February 14, 2007 that would work if you escaped the query string like "SELECT * from ".L_EstDb." WHERE...." otherwise, you can't parse a constant within a string, no matter what you'll probably end up hunting down all the sql calls. easiest to use a code editor and use replace function Quote Link to comment https://forums.phpfreaks.com/topic/38413-solved-using-an-alias-to-a-database-name-in-a-query/#findComment-184286 Share on other sites More sharing options...
fenway Posted February 14, 2007 Share Posted February 14, 2007 Well, if you had your queries in double-quotes, you could interpolate a $dbName variable... but I'm not a proponent of that method. Quote Link to comment https://forums.phpfreaks.com/topic/38413-solved-using-an-alias-to-a-database-name-in-a-query/#findComment-184296 Share on other sites More sharing options...
_giles_ Posted February 14, 2007 Author Share Posted February 14, 2007 ".L_EstDb." works just fine for me ... THANK YOU! Quote Link to comment https://forums.phpfreaks.com/topic/38413-solved-using-an-alias-to-a-database-name-in-a-query/#findComment-184491 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.