我想创建一个使用PDO和PostgreSql数据库在php中登录的简单脚本。我在Postgre和这些脚本中创建了数据库。第一个脚本叫做cbconnection.php:
<?php session_start(); $conn=pg_connect( "dbname=gestionelavori user=gestionelavori password=gestionelavori port=5432 "); $stat=pg_connection_status($conn); if ($stat===P GSQL_CONNECTION_OK) { echo 'Connection status ok'; } else { echo
'Connection status bad'; } include_once 'utente.php'; $utente=new Utente($conn); ?>
另一个脚本是utente.php:
<!DOCTYPE HTML>
<html>
<title>Sistema di Gestione Rapporti Lavoro
</title>
<head>
</head>
<body>
<form method="post">
<div class="form-group">
<input type="text" class="form-control" name="nome_utente" placeholder="Username or E mail ID" required />
</div>
<div class="form-group">
<input type="password" class="form-control" name="password" placeholder="Your Password" required />
</div>
<div class="clearfix"></div>
<hr />
<div class="form-group">
<button type="submit" name="btn-login" class="btn btn-block btn-primary">
<i class="glyphicon glyphicon-log-in"></i> SIGN IN
</button>
</div>
</form>
<?php include_once 'dbconnection.php'; class Utente{ private $db; function __construct($conn) { $this->db = $conn; } public function login($nome_utente,$password) { try { $stmt = $this->db->prepare("SELECT * FROM utente WHERE nome_utente=nome_utente "); $stmt->execute(array('nome_utente'=>$nome_utente)); $utenteRow=$stmt->fetch(PDO::FETCH_ASSOC); if($stmt->rowCount()
> 0) { if($password, $utenteRow['password']) { $_SESSION['utente_session'] = $utenteRow['id_utente']; return true; } else { return false; } } } catch(PDOException $e) { echo $e->getMessage(); } } public function is_loggedin() { if(isset($_SESSION['utente_session']))
{ return true; } } } ?>
</body>
</html>
问题是我在页面中看不到任何内容。我有什么错误或我应该修复的东西吗?我是PDO的新手。谢谢!