【发布时间】:2014-12-27 07:50:49
【问题描述】:
我有这个错误
致命错误:未捕获的异常“PDOException”和消息“SQLSTATE[3D000]:无效的目录名称:1046 未选择数据库”在 /srv/users/wiput/apps/gallery/public/auth.php:56 堆栈跟踪: #0 /srv/users/wiput/apps/gallery/public/auth.php(56): PDOStatement->execute() #1 {main} 在 /srv/users/wiput/apps/gallery/public/auth 中抛出。 php 在第 56 行
在 con.inc.php 中
<?
$db_server = "localhost";
$db_user = "gallery";
$db_password = "<censored>";
$db_name = "gallery";
$conn = new PDO("mysql:server=$db_server;Database=$db_name",$db_user,$db_password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
?>
在 auth.php 中
<?
ob_start();
session_start();
//Global Variable
$username = $_REQUEST["username"];
$password = $_REQUEST["password"];
//Convert to MD5
$md5_pw = md5($password);
//Check Blank form
if($username == '')
{
$_SESSION["error"] = 2;
header("location:index.php");
}
elseif($password == '')
{
$_SESSION["error"] = 3;
header("location:index.php");
}
else
{
//Connect file
require("con.inc.php");
//Check data
$sql = "SELECT * FROM member WHERE username= :username AND password= :md5_pw ";
$result = $conn->prepare($sql);
$result->bindValue(':username', $username);
$result->bindValue(':md5_pw', $md5_pw);
$result->execute();
$data = $result->fetchAll( PDO::FETCH_ASSOC );
if ($data !== false)
{
echo 'Hi! ', $data['firstname'];
}
else
{
$_SESSION["error"] = 1;
header("location:index.php");
}
}
?>
我使用带有 PHP 5.6 的 serverpilot Web 服务器。 如果有人可以请修复它。 谢谢你:)
【问题讨论】: