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"; 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 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 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). 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... 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
Archived
This topic is now archived and is closed to further replies.