I am creating an install file for a script I created and will also provide the fields to enter the database details. Anyway, before storing those database details in a config.php file, I’d like to see if they work. What would be the best way to see if the provided details are valid? I thought of running a dummy query and if it’s successful then store the details in a file. I don’t know what the best query would be? I am using PDO for the whole thing. So, I basically need to check if a database connection succeeded in order to continue.
Could you please tell me your ideas how to verify if everything is alright with the user input? Is my dummy query idea a good way to handle this? If yes, what query should I run? If no, what do you suggest?
Thanks.
First of all, check if PHP connects to the database correctly (returned values, mysql errors). Then You can use something like
SHOW VARIABLES LIKE "%version%"to determine the database engine version, so all functions and methods will work as intended. This way You can also inform Your users, that their db version is to old to be used with Your software.EDIT
Also, a query of
SHOW GRANTS FOR 'user'@'host'is a good idea to check permissions for connected user