Try this... took me about 30 minutes to come up with this so I hope this was time well spent!
Database Test Instructions
1) Download the most stable version of phpMyAdmin from http://www.phpmyadmin.net
2) Install it on your system off the root (htdocs for Apache; wwwroot for IIS)
3) Edit phpMyAdmin's config.inc.php:
For this test, allow database drops (test.sql will have a sql command to drop it)
$cfg['AllowUserDropDatabase'] = TRUE;
Set the server info:
$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = 'password for root account';
4) Run phpMyAdmin from your browser (http://localhost/phpMyAdmin)
a) Name your database to be 'Test'
b) Choose latin1 binary collation
c) Click the create button to create the database
d) Click on the SQL tab
e) Cut and paste Test.sql (see below) in the "Run SQL query/queries on database" box
f) Click the Go button to run this SQL query
g) You should now have a Test database with 4 records in a Users table
h) Browse the Users table to prove to yourself that it exists
5) Create a PHP script file called DBTest.php (see below)
#---------------------------------------
#Test.sql
#---------------------------------------
--------------------------------------
Drop the Test database
--------------------------------------
DROP DATABASE Test;
------------------------------------
Create Test database
------------------------------------
CREATE DATABASE Test DEFAULT CHARACTER SET latin1 COLLATE latin1_bin;
------------------------------------
Use Test database
------------------------------------
USE Test;
------------------------------------
Create a Users table
------------------------------------
CREATE TABLE Users (
idUsers INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
username VARCHAR(20) NULL,
joinDate TIMESTAMP NULL,
PRIMARY KEY(idUsers)
) Type=MYISAM;
------------------------------------
Insert some user records
------------------------------------
insert into Users (idUsers, username, joinDate) values (1, 'john kobashi', 20050101120000);
insert into Users (idUsers, username, joinDate) values (2, 'helen kobashi', 20050201120000);
insert into Users (idUsers, username, joinDate) values (3, 'kerry kobashi', 20050301120000);
insert into Users (idUsers, username, joinDate) values (4, 'mitzi kobashi', 20050401120000);
<?php
// ============================================
// File: DBTest.php
// Purpose: Test the mySQL database connection and print out some records
//
// Note: Change the password in the connection line below
// ============================================
echo "Start database test. <br />";
// Connect to mySQL
$dbLink = mysql_connect("localhost", "root", "yourpasswordhere");
if ($dbLink == FALSE)
echo "Cannot connect to database<br />";
// Select the Test database
if (mysql_select_db("Test", $dbLink) == FALSE)
echo "Cannot select database<br />";
// List out the users table
$result = mysql_query("SELECT idUsers, username, joinDate FROM Users");
if (!$result)
{
echo "Could not run query: " . mysql_error();
exit;
}
while ($row = mysql_fetch_row($result))
{
echo "UserId: " . $row[0] . "<br />";
echo "Username: " . $row[1] . "<br />";
echo "JoinDate: " . $row[2] . "<br />";
}
// Now close it
if (mysql_close($dbLink) == FALSE)
echo "Cannot disconnect from database<br />";
echo "End database test. <br />";
?>