forgot file and maybe min compatible php 5.5

This commit is contained in:
Nereziel
2024-02-03 16:43:50 +01:00
parent eb6cdfc98d
commit 8f0e8a0a63
3 changed files with 101 additions and 28 deletions

View File

@@ -17,11 +17,12 @@ class DataBase {
try {
// Establish a connection to the database using PDO
$this->PDO = new PDO(
"mysql:host=".DB_HOST."; port=".DB_PORT."; dbname=".DB_NAME,
"mysql:host=".DB_HOST.";port=".DB_PORT.";dbname=".DB_NAME,
DB_USER,
DB_PASS,
array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8")
DB_PASS
);
// Set the connection to use utf8 encoding
$this->PDO->exec("SET NAMES utf8");
}
catch(PDOException $ex) {
// Display error message if connection fails
@@ -37,14 +38,16 @@ class DataBase {
* @param array $bindings An associative array of parameters and their values.
* @return array|false Returns an array of rows as associative arrays or false if no results are found.
*/
public function select($query, $bindings = []) {
public function select($query, $bindings = array()) {
// Prepare and execute the SQL query
$STH = $this->PDO->prepare($query);
$STH->execute($bindings);
// Fetch the results as associative arrays
$result = $STH->fetchAll(PDO::FETCH_ASSOC);
$result ??= false; // Set $result to false if it's null
if ($result === false) {
$result = array(); // Set $result to an empty array if no results found
}
return $result;
}
@@ -55,9 +58,9 @@ class DataBase {
* @param array $bindings An associative array of parameters and their values.
* @return bool Returns true on success or false on failure.
*/
public function query($query, $bindings = []) {
public function query($query, $bindings = array()) {
// Prepare and execute the SQL query
$STH = $this->PDO->prepare($query);
return $STH->execute($bindings);
}
}
}