<?php
class Database
{
private $db;
private $host;
private $user;
private $password;
private $database;
private $types = [
'string' => 's',
'integer' => 'i'
];
public function __construct($host, $user, $password, $database) {
$this->host = $host;
$this->user = $user;
$this->password = $password;
$this->database = $database;
$this->db = new MySQLi($host, $user, $password, $database);
if ($this->db->connect_errno)
throw new Exception('Failed to connect to the MySQL database: ' . $this->db->connect_error);
}
public function query($query, $params = []) {
$statement = $this->db->prepare($query);
if (!$statement)
throw new Exception('Preparing statement faile: ' . $this->db->error);
$typeStr = '';
foreach ($params as $param) {
$type = gettype($param);
if (!array_key_exists($type, $this->types))
throw new Exception('Variable has no known type: ' . $param);
$typeStr .= $this->types[$type];
}
Строка 44 ниже
43 if (count($params) > 0) {
44 $bind = $statement->bind_param($typeStr, ...$params);
45 if (!$bind)
46 throw new Exception('Binding parameters failed: ' . $statement->error);
47 }
$exec = $statement->execute();
if (!$exec)
throw new Exception('Binding parameters failed: ' . $statement->error);
$result = $statement->get_result();
$statement->close();
return $result;
}
}
class Database
{
public $db;
public function __construct($host, $user, $password, $database)
{
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$this->db = new MySQLi($host, $user, $password, $database);
$this->db->set_charset("utf8mb4");
}
13 public function query($query, $params = [], $types= '') {
14 $types = $types ?: str_repeat("s", count($params));
15 $stmt = $this->db->prepare($query);
16 $stmt->bind_param($types, ...$params);
17 $stmt->execute();
18 return $stmt;
}
public function select($query, $params = [], $types= '') {
if (!$params) {
return $this->db->query($query);
} else {
return $this->query($query, $params)->get_result();
}
}
}
class Database
{
public $db;
public function __construct($host, $user, $password, $database)
{
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$this->db = new MySQLi($host, $user, $password, $database);
$this->db->set_charset("utf8mb4");
}
public function query($query, $params = [], $types= '') {
$types = $types ?: str_repeat("s", count($params));
$stmt = $this->db->prepare($query);
$stmt->bind_param($types, ...$params);
$stmt->execute();
return $stmt;
}
public function select($query, $params = [], $types= '') {
if (!$params) {
return $this->db->query($query);
} else {
return $this->query($query, $params)->get_result();
}
}
}
$bind = $statement->bind_param($typeStr, ...$params);
<?php
// Includes
require __DIR__.'/includes/db.php';
phpinfo()
// Define security Variable
$pSecurity = $_POST['security'];
// Start Hourboost
if (array_key_exists('username', $_POST) && array_key_exists('password', $_POST) && array_key_exists('games', $_POST)) {
$sUser = $_POST['username'];
$sPass = $_POST['password'];
$sGames = $_POST['games'];
$sUserHTML = htmlspecialchars($sUser, ENT_QUOTES);
// Search for duplicate account
$dupUser = $db->query('SELECT username FROM accounts WHERE username=?', [
$sUser
]);
$dupUser = $dupUser->fetch_assoc();
// Convert dupUser Array to String
$dupUserString = implode("", $dupUser);
// If account already in database
if ($dupUser > 0) {
//do nothing
} else {
if ($pSecurity == 1 && array_key_exists('mobileAuth', $_POST)) {
$sAuth = $_POST['mobileAuth'];
// Insert into database
$db->query('INSERT INTO accounts (username, password, secret, games) VALUES (?, ?, ?, ?)', [
$sUser,
$sPass,
$sAuth,
$sGames
]);
} else if ($pSecurity == 2 && array_key_exists('steamGuard', $_POST)) {
$sGuard = $_POST['steamGuard'];
// Insert into database
$db->query('INSERT INTO accounts (username, password, sentry, games) VALUES (?, ?, ?, ?)', [
$sUser,
$sPass,
$sGuard,
$sGames
]);
} else if ($pSecurity === NULL) {
// Insert into database
$db->query('INSERT INTO accounts (username, password, games) VALUES (?, ?, ?)', [
$sUser,
$sPass,
$sGames
]);
} else {
// Insert into database
$db->query('INSERT INTO accounts (username, password, games) VALUES (?, ?, ?)', [
$sUser,
$sPass,
$sGames
]);
}
}
}
?>
Удалил, просто хотел показать человеку ниже какая версияНу так во первых ты после пхпинфо точку с запятой не поставил, конечно она ошибку будет выдавать. Удалил - что теперь не работает?
phpinfo()