SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Jun 2008
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    500 error on php mysql test script

    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.

    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" ;

    ?>
    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:

    <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>
    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.

  2. #2
    SitePoint Enthusiast
    Join Date
    May 2004
    Location
    London, United Kingdom
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Turn off browser friendly errors: http://www.witsuite.com/support/know...r-messages.php
    enable display_errors in PHP.ini and tell us the exact error message you have.
    CodeReview4U - boost your code and skills for
    being social - JavsScript and C# code reviews.

  3. #3
    SitePoint Member
    Join Date
    Jun 2008
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok after having to walk the "web server administrator" through turning on the display_errors (I swear anyone can get a web server admin position now a days) I am getting the following error for the script I posted first.

    Fatal error: Call to undefined function mysql_pconnect() in line 15

    line 15 is...

    PHP Code:
    $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 
    Seems that the mysql part of the php install may not have been configured correctly. Am I on the right track??

  4. #4
    SitePoint Enthusiast
    Join Date
    May 2004
    Location
    London, United Kingdom
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The php_mysql extension is not enabled, look at the manual and select installation method that is suitable for you: http://php.net/manual/en/mysql.installation.php

    On Windows you need to uncomment the line ;extension=php_mysql.dll, on Linux you may need to recompile PHP.
    CodeReview4U - boost your code and skills for
    being social - JavsScript and C# code reviews.

  5. #5
    SitePoint Member
    Join Date
    Jun 2008
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think I got if figured out. PHP 4 had embedded support for MySQL but PHP5 has removed embedded support for MySQL and requires MySQL to be loaded as an add-in module, in the same way you have to support anything else.
    I made sure that line was uncommented, downloaded the missing dll files and updated the php.ini to include extension_dir, the correct file path for the dll. Man have I mentioned that Windows is a drag.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •