您好,我正在尝试使用 PDO 登录,但遇到了一些问题。我总是收到 Kazkas blogai 消息。实际上,我不知道我的代码问题在哪里。以下是 PHP 代码示例:
<?php
session_start();
$user = "asgasgasg";
$pass = "jhgjkghjghj";
/* Pirmas etapas */
if(isset($_POST['accept'])){
try {
$connect = new PDO('mysql:host=localhost;dbname=abba_sql', $user, $pass);
$connect->exec("SET CHARACTER SET utf8");
$name=$_POST['name'];
$pass=$_POST['pass'];
$iname=htmlspecialchars($name);
$ipass=htmlspecialchars($pass);
/* Antras etapas */
$sql = $connect->prepare("select * from FOO WHERE name = :name AND pass = :pass");
$sql->execute(array(':name' => $iname, ':pass' => $ipass));
$rows = $sql->fetchAll();
$rowcount = count($rows);
if($rowcount > 0){
$_SESSION['login'] = "1";
echo 'Viskas ciki';
}
else
{
echo 'Kazkas blogai';
}
$connect = null;
}
catch(PDOException $e) {
echo $e->getMessage();
}
}
else {
?>
如果你能帮助我,我会很高兴。我正在尝试了解 PDO 基础知识。感谢您的建议和帮助。