Skip to content

Instantly share code, notes, and snippets.

@nfreader

nfreader/db.php Secret

Last active May 17, 2024 13:48
Show Gist options
  • Save nfreader/16cfd5ea11fa46077fb02e2781c02de5 to your computer and use it in GitHub Desktop.
Save nfreader/16cfd5ea11fa46077fb02e2781c02de5 to your computer and use it in GitHub Desktop.
<?php
// $this->qb() returns an instance of \Doctrine\DBAL\Query\QueryBuilder from \Doctrine\DBAL\Connection
public function insertNewRank(
string $name,
int $flags
): int {
$qb = $this->qb();
$qb->insert(self::TABLE)
->values([
'name' => $qb->createNamedParameter($name),
'flags' => $qb->createNamedParameter($flags)
])->executeStatement();
return (int) $this->connection->lastInsertId();
}
//Params here are passed straight from $_POST
public function insertUser(
string $firstName,
string $lastName,
string $email,
string $password
): ?int {
try {
$qb = $this->qb();
$qb->insert(self::TABLE)
->values([
'firstName' => $qb->createNamedParameter($firstName),
'lastName' => $qb->createNamedParameter($lastName),
'email' => $qb->createNamedParameter($email),
'password' => $qb->createNamedParameter($password),
'created_ip' => $qb->createNamedParameter(ip2long($_SERVER['REMOTE_ADDR']))
])->executeStatement();
return (int) $this->connection->lastInsertId();
} catch (Exception $e) {
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment