Jump to content
Larry Ullman's Book Forums
masterlayouts

Can We Pass Dynamically Table Names Using Prepared Statements?

Recommended Posts

You *can* but you can't use a table name as a parameter, which means it has to be a variable. That means you have to run the variable through an escaping function to make it safe to use.

Share this post


Link to post
Share on other sites

Passing it like a variable it means something like this:

 

q = 'SELECT email FROM ' . $tableName . ' WHERE id=? LIMIT 1';

 

When you make a function or create a class to work with the database it make sense to have the table passed dynamically. Certainly, I was looking for something parameter wise, I just wanted to be sure I do not miss something. Thank you for your help.

Share this post


Link to post
Share on other sites

I knew what you meant, and I was suggesting something like populating an array with the names of the tables, and then looping through the array, making a new prepared statement for each table. After that, you could access any table using prepared statements.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...