-
-
Save nfreader/16cfd5ea11fa46077fb02e2781c02de5 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 | |
// $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