PHP无法与MYSQL数据库通信

时间:2014-04-14 01:56:22

标签: php mysql

我只是在看一些关于拍卖网站如何工作的编码(在幕后,我将在后面开始我自己)所以我给了这个免费的一个,但是我有一个查看代码,但无法弄清楚它为什么不起作用!

希望你们能在这里帮助我:\

<?php
002
/***************************************************************************
003
*   copyright              : (C) 2008 - 2013 WeBid
004
*   site                   : http://www.webidsupport.com/
005
***************************************************************************/
006

007
/***************************************************************************
008
*   This program is free software; you can redistribute it and/or modify
009
*   it under the terms of the GNU General Public License as published by
010
*   the Free Software Foundation; either version 2 of the License, or
011
*   (at your option) any later version. Although none of the code may be
012
*   sold. If you have been sold this script, get a refund.
013
***************************************************************************/
014

015 session_start();
016 include 'functions.php';
017 define('InInstaller', 1);
018

019 $main_path = getmainpath();
020 $thisversion = this_version();
021 echo print_header(false);
022

023 $step = (isset($_GET['step'])) ? $_GET['step'] : 0;
024 switch($step)
025 {
026    case 2:
027        $siteURL = urldecode($_GET['URL']);
028        $siteEmail = $_GET['EMail'];
029        include '../includes/config.inc.php';
030        include 'sql/dump.inc.php';
031        $queries = count($query);
032        if (!mysql_connect($DbHost, $DbUser, $DbPassword))
033        {
034            die('<p>Cannot connect to ' . $DbHost . '</p>');
035
    }
036        if (!mysql_select_db($DbDatabase))
037        {
038            die('<p>Cannot select database</p>');
039        }
040        echo ($_GET['n'] * 25) . '% Complete<br>';
041        $from = (isset($_GET['from'])) ? $_GET['from'] : 0;
042        $fourth = floor($queries/4);
043        $to = ($_GET['n'] == 4) ? $queries : ($fourth * $_GET['n']);
044        for ($i = $from; $i < $to; $i++)
045        {
046            mysql_query($query[$i]) or die(mysql_error() . "\n\t" . $query[$i]);
047        }
048        flush();
049
    if ($i < $queries)
050
    {
051 echo '<script type="text/javascript">window.location = "install.php?    
step=2&URL=' . urlencode($_GET['URL']) . '&EMail=' . $_GET['EMail'] . '&cats=' .          $_GET['cats'] . '&n=' . ($_GET['n'] + 1) . '&from=' . $i . '";</script>';
052
    }
053        else
054        {
055            echo '<p>Installation complete.</p>
056                <p>What do I do now?</p>
057
            <ul>
058                    <li>Your WeBid password salt: <span style="color: #FF0000; font-    weight:bold;">' . $_SESSION['hash'] . '</span> You should make note of this random code, it     is used to secure your users passwords. It is stored in your config file if you accidently delete this file and don\'t have this code all your users will have to reset their passwords</li>
059                    <li>Remove the install folder from your server. You will not be     able to use WeBid until you do this.</li>
060                    <li>Finally set-up your admin account <a href="' . $_GET['URL']  . 'admin/" style="font-weight:bold;">here</a></li>
061                    <li>Maybe check out our <a href="http://www.webidsupport.com/forums/">support forum</a></li>
062                </ul>';
063        }
064        break;
065    case 1:
066        if (!mysql_connect($_POST['DBHost'], $_POST['DBUser'], $_POST['DBPass']))
067        {
068            die('<p>Cannot connect to ' . $DbHost . ' with the supplied username and password. <a href="#" onclick="history.go(-1)">Go Back</a></p>');
069        }
070        if (!mysql_select_db($_POST['DBName']))
071        {
072            die('<p>Cannot select database ' . $_POST['DBName'] . '. <a href="#" onclick="history.go(-1)">Go Back</a></p>');
073        }
074        $cats = (isset($_POST['importcats'])) ? 1 : 0;
075        echo '<b>Step 1:</b> Writing config file...<br>';
076        $path = (!get_magic_quotes_gpc()) ? str_replace('\\', '\\\\', $_POST['mainpath']) : $_POST['mainpath'];
077        $hash = md5(microtime() . rand(0,50));
078        $_SESSION['hash'] = $hash;
079        // generate config file
080        $content = '<?php' . "\n";
081        $content .= '$DbHost     = "' . $_POST['DBHost'] . '";' . "\n";
082        $content .= '$DbDatabase = "' . $_POST['DBName'] . '";' . "\n";
083        $content .= '$DbUser     = "' . $_POST['DBUser'] . '";' . "\n";
084        $content .= '$DbPassword = "' . $_POST['DBPass'] . '";' . "\n";
085        $content .= '$DBPrefix  = "' . $_POST['DBPrefix'] . '";' . "\n";
086        $content .= '$main_path = "' . $path . '";' . "\n";
087        $content .= '$MD5_PREFIX = "' . $hash . '";' . "\n";
088        $content .= '?>';
089        $output = makeconfigfile($content, $path);
090        if ($output)
091        {
092            $check = check_installation();
093            if ($check)
094            {
095                echo '<p>You appear to already have an installation on WeBid running would you like to do a <a href="update.php">upgrade instead?</a></p>';
096            }
097            echo 'Complete, now to <b><a href="?step=2&URL=' . urlencode($_POST['URL']) . '&EMail=' . $_POST['EMail'] . '&cats=' . $cats . '&n=1">step 2</a></b>';
098        }
099        else
100        {
101            echo 'WeBid could not automatically create the config file, please could you enter the following into config.inc.php (this file is located in the includes directory)';
102            echo '<p><textarea style="width:500px; height:500px;">
103'.$content.'
104            </textarea></p>';
105            echo 'Once you\'ve done this, you can continue to <b><a href="?step=2&URL=' . urlencode($_POST['URL']) . '&EMail=' . $_POST['EMail'] . '&cats=' . $cats . '&n=1">step 2</a></b>';
106        }
107        break;
108    default:
109        $check = check_installation();
110
    if ($check)
111        {
112            echo '<p>You appear to already have an installation on WeBid running would you like to do a <a href="update.php">upgrade instead?</a></p>';
113        }
114        echo show_config_table(true);
115    break;
116}
117 
118 ?>

但在前端我收到此错误

WeBid Installer v1.1.1


Warning: mysql_connect(): php_network_getaddresses: getaddrinfo failed: No such host is     known. in C:\xampp\htdocs\WeBid\install\install.php on line 66

Warning: mysql_connect(): php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\xampp\htdocs\WeBid\install\install.php on line 66

Notice: Undefined variable: DbHost in C:\xampp\htdocs\WeBid\install\install.php on line 68
Cannot connect to with the supplied username and password. Go Back

这里的问题是什么? 我已经为sa用户输入了用户名和密码 - 但它仍然说错误的用户名/密码 - 我想知道它的用户名和密码是否正确。

任何帮助都会很棒!

编辑 - 这是阻止它与之通信的唯一因素 - 用户名和密码 - 如果是这样,是否有人知道如何将新用户添加到新数据库,我可以更改用户名和密码以使其正常工作?

2 个答案:

答案 0 :(得分:0)

我把它作为评论开始,但是,哇这个剧本是.....哇。

错误不是用户名/密码,它无法从某些$ _POST数据中找到主机,然后它正在尝试“死”()&#39;并在错误消息中使用变量$ DBHost(在其他任何地方都没有设置),因此它没有在那里正常失败。

当它最终死亡时,它会因用户名/密码错误而死,但这不是因为用户名/密码错误而是因为连接从未启动而生成。

现在谈到真正的问题,如果这个脚本存在于互联网上的服务器上,我可能会用它在大约10分钟内破解网站数据库,事实上(如果我有用户名和密码)我可以使用你的脚本输出别人的数据库。为什么你通过POST数据传递DB登录信息?我希望至少你使用HTTPS这样做。

总的来说,这个剧本很乱,很清楚它是拼凑在一起并稍微修改而没有任何真正的理解。我很抱歉,如果这很苛刻,但是当你把几段代码放在一起而不知道他们做了什么正确时,你就不知道发生了什么。你可以自己解决你遇到的各种错误。

你没有转义/清除变量,你有意大利面条代码if / else嵌套在switch条件中。

我再次道歉,如果我遇到苛刻,我明白我们都必须从某个地方开始,有时学习很难,因为过时的信息,但编码你需要在你之前了解一些基础知识启动。

请至少让本网站查看http://www.phptherightway.com/

答案 1 :(得分:-1)

您已使用未使用值定义的$dbhost变量。所以如果你检查一下它会起作用。