When developing web sites and applications, it is often useful to be able to perform a quick check to make sure that the database connection is working properly.
The PHP script given below can be used to check a MySQL database connection.
<html><head><title>Test MySQL Database Connection</title></head>
<body>
<?php
//Assign the name of the database to the variable $db.
$db="databasename";
//Connect to MySQL server.
$link = mysql_connect("hostname", "username", "password");
//If the connection cannot be made, display an error message.
if (! $link)
die("Cannot connect to MySQL");
//Select the database. If the database cannot be selected, display an error message.
mysql_select_db($db , $link)
or die("Select DB Error: ".mysql_error());
//Close connection to MySQL server.
mysql_close($link);
?>
</body>
</html>
If your SQL server will need to accept thousands of connections each minute, consider a Dell cloud computing solution with a MySQL package.
Author: Backrubber
John Dixon Technology Ltd
Go back to MySQL Tutorials home page
Go back to Tutorials home page
Earnings Tracker is John Dixon Technology's FREE accounting and bookkeeping software tool.
Aimed at contractors and freelancers, Earnings Tracker enables you to perform bookkeeping and accounting tasks, helping you to keep track of your company's revenue and spending.
The software enables invoice amounts, expenses, pension contributions, and salaries to be recorded, and calculates the amount of corporation tax due, and the dividend distributions that can be made to shareholders.
The software is written in PHP and MySQL and is available to use for FREE online, or as a FREE download.
Earnings Tracker can also be used simply as a dividend, corporation tax, or VAT calculator.
|
|
|
|
|