added missing named parameters, added strict_types
Signed-off-by: tracer <tracer@24unix.net>
This commit is contained in:
parent
518c4ae90d
commit
707415e9c5
|
@ -1,7 +1,8 @@
|
||||||
<?php
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
namespace App\Controller;
|
namespace App\Controller;
|
||||||
|
|
||||||
|
error_reporting(error_level: E_ALL);
|
||||||
|
|
||||||
use PDO;
|
use PDO;
|
||||||
use PDOException;
|
use PDOException;
|
||||||
|
|
||||||
|
@ -20,12 +21,13 @@ class NameserverController
|
||||||
*/
|
*/
|
||||||
public function findAll(): bool|array
|
public function findAll(): bool|array
|
||||||
{
|
{
|
||||||
$statement = "
|
$sql = "
|
||||||
SELECT id, name, a, aaaa, apikey
|
SELECT id, name, a, aaaa, apikey
|
||||||
FROM " . DatabaseConnection::TABLE_NAMESERVERS;
|
FROM " . DatabaseConnection::TABLE_NAMESERVERS;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$statement = $this->databaseConnection->getConnection()->query($statement);
|
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
|
||||||
|
$statement->execute();
|
||||||
return $statement->fetchAll(mode: PDO::FETCH_ASSOC);
|
return $statement->fetchAll(mode: PDO::FETCH_ASSOC);
|
||||||
} catch (PDOException $e) {
|
} catch (PDOException $e) {
|
||||||
exit($e->getMessage());
|
exit($e->getMessage());
|
||||||
|
@ -46,10 +48,10 @@ class NameserverController
|
||||||
WHERE name = :name";
|
WHERE name = :name";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$statement = $this->databaseConnection->getConnection()->prepare($sql);
|
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
|
||||||
$statement->bindParam(param: ':name', var: $name);
|
$statement->bindParam(param: ':name', var: $name);
|
||||||
$statement->execute();
|
$statement->execute();
|
||||||
return $statement->fetch(PDO::FETCH_ASSOC);
|
return $statement->fetch(mode: PDO::FETCH_ASSOC);
|
||||||
} catch (PDOException $e) {
|
} catch (PDOException $e) {
|
||||||
exit($e->getMessage());
|
exit($e->getMessage());
|
||||||
}
|
}
|
||||||
|
@ -69,10 +71,10 @@ class NameserverController
|
||||||
WHERE id = :id";
|
WHERE id = :id";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$statement = $this->databaseConnection->getConnection()->prepare($sql);
|
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
|
||||||
$statement->bindParam(param:':id', var: $id);
|
$statement->bindParam(param:':id', var: $id);
|
||||||
$statement->execute();
|
$statement->execute();
|
||||||
return $statement->fetch(PDO::FETCH_ASSOC);
|
return $statement->fetch(mode: PDO::FETCH_ASSOC);
|
||||||
} catch (PDOException $e) {
|
} catch (PDOException $e) {
|
||||||
exit($e->getMessage());
|
exit($e->getMessage());
|
||||||
}
|
}
|
||||||
|
@ -85,16 +87,16 @@ class NameserverController
|
||||||
* @param String $aaaa
|
* @param String $aaaa
|
||||||
* @param String $apikey
|
* @param String $apikey
|
||||||
*
|
*
|
||||||
* @return int
|
* @return string|false
|
||||||
*/
|
*/
|
||||||
public function insert(String $name, String $a, String $aaaa, String $apikey): int
|
public function insert(String $name, String $a, String $aaaa, String $apikey): bool|string
|
||||||
{
|
{
|
||||||
$sql = "
|
$sql = "
|
||||||
INSERT INTO " . DatabaseConnection::TABLE_NAMESERVERS . " (name, a, aaaa, apikey)
|
INSERT INTO " . DatabaseConnection::TABLE_NAMESERVERS . " (name, a, aaaa, apikey)
|
||||||
VALUES (:name, :a, :aaaa, :apikey)";
|
VALUES (:name, :a, :aaaa, :apikey)";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$statement = $this->databaseConnection->getConnection()->prepare($sql);
|
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
|
||||||
$statement->bindParam(param: ':name', var: $name);
|
$statement->bindParam(param: ':name', var: $name);
|
||||||
$statement->bindParam(param: ':a', var: $a);
|
$statement->bindParam(param: ':a', var: $a);
|
||||||
$statement->bindParam(param: ':aaaa', var: $aaaa);
|
$statement->bindParam(param: ':aaaa', var: $aaaa);
|
||||||
|
@ -119,7 +121,7 @@ class NameserverController
|
||||||
*/
|
*/
|
||||||
public function update(Int $id, String $name, String $a, String $aaaa, String $apikey): bool|int
|
public function update(Int $id, String $name, String $a, String $aaaa, String $apikey): bool|int
|
||||||
{
|
{
|
||||||
$current = $this->findByID($id);
|
$current = $this->findByID(id: $id);
|
||||||
|
|
||||||
if (empty($name)) {
|
if (empty($name)) {
|
||||||
$name = $current['name'] ?? '';
|
$name = $current['name'] ?? '';
|
||||||
|
@ -143,7 +145,7 @@ class NameserverController
|
||||||
WHERE id = :id";
|
WHERE id = :id";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$statement = $this->databaseConnection->getConnection()->prepare($sql);
|
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
|
||||||
$statement->bindParam(param: 'id', var: $id);
|
$statement->bindParam(param: 'id', var: $id);
|
||||||
$statement->bindParam(param: 'name', var: $name);
|
$statement->bindParam(param: 'name', var: $name);
|
||||||
$statement->bindParam(param: 'a', var: $a);
|
$statement->bindParam(param: 'a', var: $a);
|
||||||
|
@ -165,12 +167,12 @@ class NameserverController
|
||||||
*/
|
*/
|
||||||
public function delete($id): int
|
public function delete($id): int
|
||||||
{
|
{
|
||||||
$statement = "
|
$sql = "
|
||||||
DELETE FROM " . DatabaseConnection::TABLE_NAMESERVERS . "
|
DELETE FROM " . DatabaseConnection::TABLE_NAMESERVERS . "
|
||||||
WHERE id = :id";
|
WHERE id = :id";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$statement = $this->databaseConnection->getConnection()->prepare($statement);
|
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
|
||||||
$statement->bindParam(param: 'id', var: $id);
|
$statement->bindParam(param: 'id', var: $id);
|
||||||
$statement->execute();
|
$statement->execute();
|
||||||
return $statement->rowCount();
|
return $statement->rowCount();
|
||||||
|
@ -186,11 +188,11 @@ class NameserverController
|
||||||
*/
|
*/
|
||||||
public function getLongestEntry(String $field): int
|
public function getLongestEntry(String $field): int
|
||||||
{
|
{
|
||||||
$statement = "
|
$sql = "
|
||||||
SELECT MAX(LENGTH(" . $field . ")) as length FROM " . DatabaseConnection::TABLE_NAMESERVERS;
|
SELECT MAX(LENGTH(" . $field . ")) as length FROM " . DatabaseConnection::TABLE_NAMESERVERS;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$statement = $this->databaseConnection->getConnection()->prepare($statement);
|
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
|
||||||
$statement->execute();
|
$statement->execute();
|
||||||
$result = $statement->fetch();
|
$result = $statement->fetch();
|
||||||
return $result['length'];
|
return $result['length'];
|
||||||
|
|
Loading…
Reference in New Issue