Skip to content

Instantly share code, notes, and snippets.

@birkir
Created February 14, 2011 11:39
Show Gist options
  • Save birkir/825759 to your computer and use it in GitHub Desktop.
Save birkir/825759 to your computer and use it in GitHub Desktop.
MySQLi
<?php
$mysqli = mysqli_connect('localhost', 'user', 'pass', 'database');
if (mysqli_connect_errno())
{
print('Gat ekki tengst.');
}
if ($stmt = $mysqli->prepare('INSERT INTO `users` (`name`, `username`, `email`, `password`) VALUES (?, ?, ?, ?)'))
{
$stmt->bind_param('sssb', 'John Doe', 'john', 'john@doe.com', hash('sha256', 'password', TRUE));
$stmt->execute();
$stmt->close();
echo $mysqli->insert_id.' var búinn til!';
}
$mysqli->close();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment