speedy33417 Posted December 6, 2008 Share Posted December 6, 2008 Is it possible to select a table from a database if I have the name of the table in a variable? Such as $sql = "SELECT settings_id FROM $thisTable WHERE blah blah"; Quote Link to comment https://forums.phpfreaks.com/topic/135822-select-table-using-a-variable/ Share on other sites More sharing options...
Gamic Posted December 6, 2008 Share Posted December 6, 2008 yes Quote Link to comment https://forums.phpfreaks.com/topic/135822-select-table-using-a-variable/#findComment-708066 Share on other sites More sharing options...
crtreedude Posted December 6, 2008 Share Posted December 6, 2008 Is it possible to select a table from a database if I have the name of the table in a variable? Such as $sql = "SELECT settings_id FROM $thisTable WHERE blah blah"; Since you are building the SQL statement as a string, you can substitute anything for table. What might be more challenging is to have something like "select setting_id from ? where blah blah" which would be attempting to subsitute the table name as a variable, which I don't think can be done easily Quote Link to comment https://forums.phpfreaks.com/topic/135822-select-table-using-a-variable/#findComment-708073 Share on other sites More sharing options...
Mchl Posted December 6, 2008 Share Posted December 6, 2008 Can't use ? for table name in prepared statements (or for column names for that matter). Quote Link to comment https://forums.phpfreaks.com/topic/135822-select-table-using-a-variable/#findComment-708086 Share on other sites More sharing options...
crtreedude Posted December 7, 2008 Share Posted December 7, 2008 Can't use ? for table name in prepared statements (or for column names for that matter). Well, you could if you passed it into a stored procedure, built a string, and executed the string... but you are right. I said it wouldn't be easy... Quote Link to comment https://forums.phpfreaks.com/topic/135822-select-table-using-a-variable/#findComment-708149 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.