Skip to content

Instantly share code, notes, and snippets.

@ineentho
Created May 19, 2015 12:06
Show Gist options
  • Save ineentho/a4ef26bf7a52acce6e14 to your computer and use it in GitHub Desktop.
Save ineentho/a4ef26bf7a52acce6e14 to your computer and use it in GitHub Desktop.
<?php
$dbh = new PDO('mysql:host=localhost;dbname=test', 'root', 'sten123');
function create_user($username, $password) {
global $dbh;
$loginStmt = $dbh->prepare('INSERT INTO users (username, password) VALUES(:username, :password)');
$loginStmt->bindValue(':username', $username);
$loginStmt->bindValue(':password', password_hash($password, PASSWORD_DEFAULT));
return $loginStmt->execute();
}
$success = create_user('Ineentho', 'sten123');
if ($success) {
echo 'User created';
} else {
echo 'User could not be created';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment