dbinformer.php

来自「这是php编的论坛的原代码」· PHP 代码 · 共 475 行 · 第 1/2 页

PHP
475
字号
            } 
            else 
            { 
                $error = true; 
                $error_msg = 'You do not have the needed functions available for ' . $available_dbms[$dbms] . '.'; 
            } 
        break; 

        case 'mysql4': 
            if (function_exists(@mysql_connect)) 
            { 
                $db = array( 
                    'choice' => 'MySQL 4.x', 
                    'connect' => @mysql_connect($dbhost, $dbuser, $dbpasswd), 
                    'select' => @mysql_select_db($dbname), 
                    'error' => @mysql_error(), 
                    'list' => @mysql_list_tables($dbname), 
                    'fetch' => @mysql_fetch_row, 
                    'close' => @mysql_close() 
                ); 
            } 
            else 
            { 
                $error = true; 
                $error_msg = 'You do not have the needed functions available for ' . $available_dbms[$dbms] . '.'; 
            } 
        break; 
             
        case 'msaccess': 
            if (function_exists(@odbc_connect)) 
            { 
                $db = array( 
                    'choice' => 'MS Access [ ODBC ]', 
                    'connect' => @odbc_connect($dbhost, $dbuser, $dbpasswd), 
                    'select' => 'na', 
                    'error' => @odbc_errormsg(), 
                    'list' => 'na', /* odbc_tables() */ 
                    'fetch' => 'na', /* odbc_fetch_row(), odbc_result_all() */ 
                    'close' => @odbc_close() 
                ); 
            } 
            else 
            { 
                $error = true; 
                $error_msg = 'You do not have the needed functions available for ' . $available_dbms[$dbms] . '.'; 
            } 
        break; 
              
        case 'postgres': 
            if (function_exists(@pg_connect)) 
            { 
                $db = array( 
                    'choice' => 'PostgreSQL 7.x', 
                    'connect' => @pg_connect('host=' . $dbhost . ' user=' . $dbuser . ' dbname=' . $dbname . ' password=' . $dbpasswd), 
                    'select' => 'na', 
                    'error' => @pg_last_error(), 
                    'list' => @pg_exec("SELECT relname FROM pg_class WHERE relkind = 'r' AND relname NOT LIKE 'pg\_%'"), /* provided by SuGa */ 
                    'fetch' => @pg_fetch_row, 
                    'close' => @pg_close() 
                ); 
            } 
            else 
            { 
                $error = true; 
                $error_msg = 'You do not have the needed functions available for ' . $available_dbms[$dbms] . '.'; 
            } 
        break;                 
        case 'mssql': 
            if (function_exists(@mssql_connect)) 
            { 
                $db = array( 
                    'choice' => 'MS SQL Server 7/2000', 
                    'connect' => @mssql_connect($dbhost, $dbuser, $dbpasswd), 
                    'select' => @mssql_select_db($dbname), 
                    'error' => @mssql_get_last_message(), 
                    'list' => 'na', 
                    'fetch' => 'na', /* mssql_fetch_row() */ 
                    'close' => @mssql_close() 
                ); 
            } 
            else 
            { 
                $error = true; 
                $error_msg = 'You do not have the needed functions available for ' . $available_dbms[$dbms] . '.'; 
            } 
        break;  

        case 'mssql-odbc': 
            if (function_exists(@odbc_connect)) 
            { 
                $db = array( 
                    'choice' => 'MS SQL Server [ ODBC ]', 
                    'connect' => @odbc_connect($dbhost, $dbuser, $dbpasswd), 
                    'select' => 'na', 
                    'error' => @odbc_errormsg(), 
                    'list' => 'na', /* odbc_tables() */ 
                    'fetch' => 'na', /* odbc_fetch_row(), odbc_result_all() */ 
                    'close' => @odbc_close() 
                ); 
            } 
            else 
            { 
                $error = true; 
                $error_msg = 'You do not have the needed functions available for ' . $available_dbms[$dbms] . '.'; 
            } 
        break;  

        default: 
            $error = true; 
            $error_msg = 'Unrecognised DBMS.'; 
        break; 
    } 
     
    if ($error == true && $error_msg != '') 
    { 
        echo '<br /><b>ERROR:</b> ' . $error_msg . '<br />'; 
    } 
    else 
    { 
        echo '<a name="what"><h3><u>What you entered</u></h3></a>'; 
        echo 'Database Type: <b>' . $db['choice']  . '</b><br />'; 
        echo 'Database Server Hostname / DSN: <b>' . $dbhost . '</b><br />'; 
        echo 'Your Database Name: <b>' . $dbname . '</b><br />'; 
        echo 'Database Username: <b>' . $dbuser .   '</b><br />'; 
        echo 'Database Password: <b>' . $dbpasswd   . '</b><br />'; 

        echo '<a name="connect"><h3><u>Connection to database</u></h3></a>'; 
         
        if (!$db['connect']) 
        { 
            echo 'You have not established a connection to <b>' . $db['choice'] . '</b>.<br />'; 
            echo '<b>ERROR:</b> <i>' . $db['error'] . '</i><br /><br />'; 
        } 
        else 
        { 
            echo 'You have established a connection to <b>' . $db['choice'] . '</b>.<br /><br />'; 
            $connect = true; 
        } 

        if ($dbms == 'msaccess' || $dbms == 'postgres' || $dbms == 'mssql-odbc')  
        {         
            /* for dbmses which have no db select function */ 
            $select = true; 
        } 
        else 
        { 
            if (!$db['select']) 
            { 
                echo 'Your database was not found.<br />'; 
                echo '<b>ERROR:</b> <i>' . $db['error'] . '</i><br />'; 
            } 
            else 
            { 
                echo 'Your database was found.<br />'; 
                $select = true; 
            } 
        } 

        if ($connect == true && $select == true) 
        { 
            echo '<a name="tables"><h3><u>Tables in database</u></h3></a>'; 
            if ($dbms == 'mysql' || $dbms == 'mysql4' || $dbms == 'postgres') 
            { 
                echo '<i>Tables with the table prefix you specified are in bold.</i>'; 
                echo '<ul>'; 
                while ($table = $db['fetch']($db['list'])) 
                {    
                    /* Highlight tables with the table_prefix specified */ 
                    if (preg_match("/^$HTTP_POST_VARS[table_prefix]/i", $table[0])) 
                    { 
                        echo '<li><b>' . $table[0] . '</b></li><br />'; 
                    } 
                    else 
                    { 
                        echo '<li>' . $table[0] . '</li><br />'; 
                    } 
                } 
                echo '</ul>'; 
            } 
            else 
            { 
                echo 'Sorry, this feature isn\'t available with ' . $db['choice'] . '.'; 
            } 

            /* defined a var which is only there if successfully connected to the database and the database is found */ 
            $all_connected = true; 
        } 

        /* Create a config file if checked and if the connection went OK */ 
        if (isset($HTTP_POST_VARS['generate_config']) && $HTTP_POST_VARS['generate_config'] == true) 
        { 
            echo '<a name="config"><h3><u>Config file</u></h3></a>'; 
            if ($all_connected != true) 
            { 
                echo 'The database has not been successfully connected to so no config file has been generated.<br />'; 
            } 
            else 
            { 
                echo 'Either copy the <b>19</b> lines below and save them as <u>config.php</u> or click on the <u>Download</u> button below. Then upload the file to your phpBB2 root directory (phpBB2/ by default). Make sure that there is nothing (this includes blank spaces) after the <u>?></u>.<br /><br />'; 

                /* Create our config file */ 
                echo '<form action="' . $HTTP_SERVER_VARS['PHP_SELF'] . '" method="post"><table cellspacing="1" cellpadding="3" border="0"><tr><td class="code">'; 
                echo make_config($dbms, $dbhost, $dbname, $dbuser, $dbpasswd, $table_prefix); 
                echo '</td></tr></table>'; 
                echo '<input type="hidden" name="dbms" value="' . $dbms . '" />'; 
                echo '<input type="hidden" name="dbhost" value="' . $dbhost . '" />'; 
                echo '<input type="hidden" name="dbname" value="' . $dbname . '" />'; 
                echo '<input type="hidden" name="dbuser" value="' . $dbuser . '" />'; 
                echo '<input type="hidden" name="dbpasswd" value="' . $dbpasswd . '" />'; 
                echo '<input type="hidden" name="table_prefix" value="' . $table_prefix . '" />'; 
                echo '<input type="hidden" name="download_config" value="true" />'; 
                echo '<br /><input type="submit" name="submit_download_config" value="Download" class="mainoption" /><br />'; 
            } 
        } 

        /* close the connection */ 
        if ($all_connected == true) 
        { 
            $db['close']; 
        } 
    } 
} 

/* And they all lived happily ever after... 
The End */ 
?> 

<br /><a href="javascript:scrollTo('0','0');"><b>Return to top</b></a> 
</td> 
</tr> 
</table> 
<div align="center"><span class="copyright">&copy; Copyright 2002 The <a href="http://www.phpbb.com/about.php" target="_phpbb" class="copyright">phpBB Group</a></span></div> 
</td> 
</tr> 
</table> 
</body> 
</html> 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?