Saturday, June 27, 2020

Testing mysql database connection using php mysqli

Sometimes you do not have mysql client in your web server to test mysql connection to database server. Using this method, you can use php, which will be available in all php based web server, to test your connection. This method is very easy to implement, just one line to do the testing. Thank you to Mr Guus for this awesome method

We are going to use var_dump with mysqli_connect functions, available in php.

$ php -r 'var_dump(mysqli_connect("", "myuser", "mypassword", "mydatabase"));'

whereby is my database ip address, myuser is my database username, mypassword is my database password, and mydatabase is the name of my database. Php -r is an option to run php command without the script tags

If the command does not throw any error, then your database connection is good to go.

No comments: