I am trouble shooting an issue that has happened during the install of a simple php calendar program. I am pretty sure the issue is the connection from the php to the database so I have been trying several test scripts to trouble shoot the issue. The following are the test scripts I have been using.
Obviously I am using my correct login info not stars. Unfortunatly it seems that all I ever get is a 500 browser error. So I switched to a more indepth php script.PHP Code:<?php
//scr_config.php - database connection script
$hostname_logon = "****" ; //replace with your database location
$database_logon = "****" ; //replace with your database name
$username_logon = "****" ; //replace with database username
$password_logon = "****" ; //replace with database password
$logon = mysql_pconnect($hostname_logon, $username_logon, $password_logon) or trigger_error(mysql_error(),E_USER_ERROR);
mysql_select_db($database_logon) or die ( "Unable to select database!" );
//redirect to this page on successfull login. If that page is in a different directory make sure to include the path.
$adminpage = "index.html" ;
?>
This also gets a 500 browser error. Am i looking at a bad php install. The only test script I can seem to get to work is the php.info one. Any ideas or advice is totally appreciated.PHP Code:
<head>
<title>MySQL Connection Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style type="text/css">
#wrapper {
width: 600px;
margin: 20px auto 0;
font: 1.2em Verdana, Arial, sans-serif;
}
input {
font-size: 1em;
}
#submit {
padding: 4px 8px;
}
</style>
</head>
<body>
<div id="wrapper">
<?php
$action = htmlspecialchars($_GET['action'], ENT_QUOTES);
?>
<?php if (!$action) { ?>
<h1>MySQL connection test</h1>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?action=test" id="mail" method="post">
<table cellpadding="2">
<tr>
<td>Hostname</td>
<td><input type="text" name="hostname" id="hostname" value="" size="30" tabindex="1" /></td>
<td>(usually "localhost")</td>
</tr>
<tr>
<td>Username</td>
<td><input type="text" name="username" id="username" value="" size="30" tabindex="2" /></td>
<td></td>
</tr>
<tr>
<td>Password</td>
<td><input type="text" name="password" id="password" value="" size="30" tabindex="3" /></td>
<td></td>
</tr>
<tr>
<td>Database</td>
<td><input type="text" name="database" id="database" value="" size="30" tabindex="4" /></td>
<td>(optional)</td>
</tr>
<tr>
<td></td>
<td><input type="submit" id="submit" value="Test Connection" tabindex="5" /></td>
<td></td>
</tr>
</table>
</form>
<?php } ?>
<?php if ($action == "test") {
$hostname = trim(stripslashes($_POST['hostname']));
$username = trim(stripslashes($_POST['username']));
$password = trim(stripslashes($_POST['password']));
$database = trim(stripslashes($_POST['database']));
$link = mysql_connect("$hostname", "$username", "$password");
if (!$link) {
echo "<p>Could not connect to the server '" . $hostname . "'</p>\n";
echo mysql_error();
}else{
echo "<p>Successfully connected to the server '" . $hostname . "'</p>\n";
}
if ($link && !$database) {
echo "<p>Database check skipped: No database name was given</p>\n";
}
if ($database) {
$dbcheck = mysql_select_db("$database");
if (!$dbcheck) {
echo mysql_error();
}else{
echo "<p>Successfully connected to the database '" . $database . "'</p>\n";
// Check tables
$sql = "SHOW TABLES FROM $database";
$result = mysql_query($sql);
if (mysql_num_rows($result) > 0) {
echo "<p>Tables in '" . $database . "':</p>\n";
echo "<ul>\n";
while ($row = mysql_fetch_row($result)) {
echo "<li>{$row[0]}</li>\n";
}
echo "</ul>\n";
} else {
echo "<p>The database '" . $database . "' contains no tables.</p>\n";
echo mysql_error();
}
}
}
}
?>
</div><!-- end #wrapper -->
</body>
</html>




Bookmarks