Created
November 9, 2014 20:08
-
-
Save andersonFaro9/9d106bb115883fa82652 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function conectar() | |
{ | |
try { | |
$email = $_POST['email']; | |
$senha = $_POST['senha']; | |
$pdo = new \PDO('mysql:dbname=banco;host=localhost', 'root', 'root'); | |
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); | |
$sql = $pdo->prepare( | |
"SELECT * FROM usuarios WHERE email = '$email' AND senha = '$senha' " | |
); | |
$sql->bindValue("email:", $email); | |
$sql->bindValue("senha:", $senha); | |
$sql->execute(); | |
if ($sql->rowCount() == 1) { | |
$dadosDoUsuario = $sql->fetch(PDO::FETCH_OBJ); | |
$_SESSION['nomeUsuario'] = $dadosDoUsuario->$dadosDoUsuario; | |
} | |
if (isset($_POST['submit'])) { | |
if (isset($_POST['email'], $_POST['senha'])) { | |
return true; | |
} | |
} | |
} catch (\PDOException $e) { | |
die("<h1>Não foi possivel estabelecer conexão," . " erro de código</h1>" . $e->getCode() . $e->getMessage()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment