Think bobby drop tables, now consider the following:
$dbh = new PDO("mysql:host=...;dbname=mysql", ...);
$dbh->query("use newdatabase");
This seems super insecure. Why would I ever want this? Because I have built my own database connection tool and the last part is allowing you to specify which database to use. My connection tool returns a \PDO
object at the end of the day regardless of which type of database server you connect to: pgsql, mysql or sqlite.
The issue with this is that if I create a setDatabase(string $database)
then you could be malicious. Is the appropriate way to do it through the connection string and then connect? Or is there a safe way where I could connect, then set the database?