How to cleanly update database from Datagridview?

What is the benefit of placing the database name in a SQL statement for PDO? (IE: UPDATE database.table)

  • I'm wondering because I'm re-working some code and noticed that my database calls reference the table as "database.table" in the string. I have a constant defined with the database name, but for some reason I didn't concatenate it into my database calls (I just use it to establish the connection). Would you concatenate the database call with this constant, or do you feel that might present issues with SQL injection?

  • Answer:

    If you have multiple databases running on the same server, and your user credentials allow access to both, you can access different databases in the same connection, do joins across them, etc. SELECT tableA.id, tableB.name FROM db1.tableA JOIN db2.tableB ON (...) If your app was accessing multiple databases, I would use that convention across the code to make it clear which database any given table is in. If you're only ever accessing a single database on the server instance, I don't know of any advantage of prepending the database name.

Jon Moter at Quora Visit the source

Was this solution helpful to you?

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.