PDO连接语句在测试服务器上运行但不在线

时间:2016-08-29 19:34:36

标签: php pdo

我有一个pdo脚本,它是一个基本的登录脚本。它在我的测试服务器上工作得很好。但在我的直播服务器上没有功能。我收到了PDO错误:

  

PHP致命错误:未捕获的异常' PDOException'消息' SQLSTATE [3D000]:无效的目录名称:1046未选择数据库'在/nas/content/live/inboundpro/leadportal/index.php:40\nStack trace:\ n#0 /nas/content/live/inboundpro/leadportal/index.php(40):PDOStatement-> execute() \ n#1 {main} \ n在第40行的/nas/content/live/inboundpro/leadportal/index.php中抛出,引用者:http://www.inboundprospect.com/leadportal/

     <?php
    session_start();

    //DB configuration Constants
    define('_HOST_NAME_', '162.242.221.151;3306');
    define('_USER_NAME_', '*******');
    define('_DB_PASSWORD', '*******');
    define('_DATABASE_NAME_', '*******');

    //PDO Database Connection
    try {
        $databaseConnection = new PDO('mysql:host='._HOST_NAME_.';dbname='._DATABASE_NAME_, _USER_NAME_, _DB_PASSWORD);
        $databaseConnection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    } catch(PDOException $e) {
        echo 'ERROR: ' . $e->getMessage();
    }

    if(isset($_POST['submit'])){
        $errMsg = '';
        //username and password sent from Form
        $username = trim($_POST['username']);
        $password = trim($_POST['password']);

        if($username == '')
            $errMsg .= 'You must enter your Username<br>';

        if($password == '')
            $errMsg .= 'You must enter your Password<br>';


        if($errMsg == ''){
            $records = $databaseConnection->prepare('SELECT id,username,password,hash FROM tbl_users WHERE username = :username');
            $records->bindParam(':username', $username);
            $records->execute();
            $results = $records->fetch(PDO::FETCH_ASSOC);
            if(count($results) > 0 && password_verify($password, $results['hash'])){
                $_SESSION['username'] = $results['username'];
                $_SESSION['logged_in'] = true;
                header('location:dashboard.php');
                exit;
            }else{
                $errMsg .= 'Username and Password are not found<br>';
            }
        }
    }
?>
<html>
<head>
<meta name="robots" content="noindex">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="viewport" content="width=device-width">
<title>Login Page PHP Script</title>
<link href="css/index.css" rel="stylesheet" type="text/css">
</head>
<html>
<body>
    <div class="front">
        <div class="center">

            <div class="LoginPortal">
                <?php
                    if(isset($errMsg)){
                        echo '<div style="color:#FF0000;text-align:center;font-size:12px;background-color:white;padding-top:5px;padding-bottom:5px;">'.$errMsg.'</div>';
                    }
                ?>
                <form action="" method="post">
                    <div class="formTop"><img src="images/IP_Logo_SOLO.png"></div>

                    <div class="Formcenter">
                    <input type="text" name="username" class="box" placeholder="USERNAME"/>
                    <input type="password" name="password" class="box" placeholder="PASSWORD"/><br />
                    <input type="submit" name='submit' value="Submit" class='submit'/>
                    </div>

                </form>
            </div><!-- close center -->
    </div>
</div>
</body>
</html>

我错过了什么?

0 个答案:

没有答案