Software, your way.
How To Get Good Custom Software
(Download)
(PDF)
burger menu icon
WillMaster

WillMaster > LibraryWebsite Owner Tools

FREE! Coding tips, tricks, and treasures.

Possibilities weekly ezine

Get the weekly email website developers read:

 

Your email address

name@example.com
YES! Send Possibilities every week!

Test MySQL Connection

Are the MySQL credentials you have correct? Use the software on this page to do a test.

Incorrectly specifying MySQL connection credentials for a software setup means going back and starting all over again.

The software further below can make the task less frustrating. Test the connection before specifying the information in the software setup page.

Provide the host name, the database name, the username, and the password. Then click the button. The test will pass or fail.

If the test passes, you can copy the data in the form fields for pasting into the software setup page.

If the connection test fails, your previous data is saved in the form fields. Simply adjust and click the button again.

The connection tester interface looks like this.

Host name.

Database name.

Username.

Password.

Here is the source code of the software. No customization required.

Important: Either put this software into a password-protected directory or remove it from your server while you're not actively using it. Leaving it publicly accessible is an invitation for hackers to try to break into your MySQL databases.

Further, accessing this software with an SSL connection, https://... URL, is prudent to avoid interception of sensitive data you provide to the software.

<?php
/*
MySQL Connection Tester
 October 8, 2016
  Will Bontrager Software LLC
   This software is provided "AS IS," without any warranty of any kind, without 
   even any implied warranty such as merchantability or fitness for a particular 
   purpose. Will Bontrager Software LLC grants you a royalty free license to use 
   this software provided this notice appears on all copies. 
*/
$Message = '';
if( count($_POST) )
{
   $MySQL = new mysqli( $_POST['Hname'], $_POST['Uname'], $_POST['pw'], $_POST['Dname'] );
   if( $MySQL->connect_error ) { $Message .= 'Connection test result: Failed<br>'.$MySQL->connect_error; }
   else { $Message .= 'Connection test result: PASSED'; }
}
?><!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Test MySQL Connection</title>
<style type="text/css">
html, body { font-size:100%; font-family: sans-serif; }
p, input { box-sizing:border-box; }
input { font-size:1em; width:100%; max-width:200px; box-sizing:border-box; }
input[type="text"] { border:1px solid #ccc; padding:.25em .5em .25em .5em; border-radius:.25em; }
</style>
</head>
<body>
<div style="display:table; margin:.5in auto; text-align:center;">
<a href="//www.willmaster.com/">
<img src="//www.willmaster.com/images/wmlogo_icon.gif" style="border:none; outline:none; width:50px; height:50px;" alt="willmaster.com logo">
</a>

<span style="font-size:2em; position:relative; vertical-align:.5em;">Willmaster.com</span>
<h3>MySQL Connection Tester</h3>

<?php if($Message): ?>
<div style="display:table; margin:1em auto; border:1px solid blue; border-radius:.25em; padding:.5em; text-align:left;">
<?php echo($Message) ?>
</div>
<?php endif; ?>

<div style="display:table; border:2px solid #ccc; padding:1em; border-radius:.5em; text-align:left; margin:0 auto;">
<form style="display:inline; margin:0;" method="post" action="<?php echo($_SERVER['PHP_SELF']) ?>">
<p style="margin:0;">
Host name.
</p>
<input name="Hname" type="text" value="<?php echo(@$_POST['Hname']) ?>">
<p style="margin-bottom:0; margin-top:.5em;">
Database name.
</p>
<input name="Dname" type="text" value="<?php echo(@$_POST['Dname']) ?>">
<p style="margin-bottom:0; margin-top:.5em;">
Username.
</p>
<input name="Uname" type="text" value="<?php echo(@$_POST['Uname']) ?>">
<p style="margin-bottom:0; margin-top:.5em;">
Password.
</p>
<input name="pw" type="text" value="<?php echo(@$_POST['pw']) ?>">
<p style="margin-bottom:0; margin-top:.5em;">
<input name="name" type="submit" value="Test Connection">
</p>
</form>
</div>

<p style="font-size:.9em;">
Copyright 2016 <a href="//www.willmaster.com/">Will Bontrager Software LLC</a>
</p>
</div>
</body>
</html>

Save the above as a .php file. To use it, upload it to your server and type its URL into your browser.

This is a wonderful tool for developers who must rely on MySQL connection data provided by clients: Upload the script. Verify the data. Remove the script.

(This article first appeared in Possibilities ezine.)

Will Bontrager

Was this article helpful to you?
(anonymous form)

Support This Website

Some of our support is from people like you who see the value of all that's offered for FREE at this website.

"Yes, let me contribute."

Amount (USD):

Tap to Choose
Contribution
Method

All information in WillMaster Library articles is presented AS-IS.

We only suggest and recommend what we believe is of value. As remuneration for the time and research involved to provide quality links, we generally use affiliate links when we can. Whenever we link to something not our own, you should assume they are affiliate links or that we benefit in some way.

How Can We Help You? balloons
How Can We Help You?
bullet Custom Programming
bullet Ready-Made Software
bullet Technical Support
bullet Possibilities Newsletter
bullet Website "How-To" Info
bullet Useful Information List

© 1998-2001 William and Mari Bontrager
© 2001-2011 Bontrager Connection, LLC
© 2011-2024 Will Bontrager Software LLC