Not sure which DB extension you're using, but I know at least some do not allow bound parameters for table/column names, in which case you'd just have to embed that variable directly into the SQL string.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
I think by engine he meant whether you're using mysqli, pdo, or something else all together. MySQLI and PDO do not support bound table/column names at all. See http://us3.php.net/manual/en/book.pdo.php#69304
Yeah, you'll have to put the variable for the table name directly in the string:
PHP Code:
"SELECT * FROM `$table` WHERE . . ."
We do something similar all the time at work with PDO using PostgreSQL, where the schema name is dynamic:
PHP Code:
$sql = "SELECT * FROM {$this->dbSchema}.table_name . . ."
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
execSQL("SELECT id FROM `$table` WHERE id=?", array('i', $u_id), style::Q_NUM_ROWS)
So it won't break something if i put a variable name in prepare statement?
Should be fine, with the exception that if the table name comes from user input or some other external source, then you'll need to sanitize it to make sure no SQL injection attacks/errors occur. With MySQLi, you can use the mysqli::real_escape_string() method.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Bookmarks