mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-23 04:59:46 +00:00
using prepared statements for PlayerAPI::get
This commit is contained in:
parent
948340b399
commit
c95a8d5cff
2 changed files with 13 additions and 2 deletions
|
|
@ -294,7 +294,10 @@ class PlayerAPI{
|
||||||
if($name === ""){
|
if($name === ""){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$query = $this->server->query("SELECT ip,port,name FROM players WHERE name = '$name';"); //try getting player by name first
|
$this->server->preparedSQL->player->getEq->reset();
|
||||||
|
$this->server->preparedSQL->player->getEq->bindValue(":name", $name);
|
||||||
|
$query = $this->server->preparedSQL->player->getEq->execute();
|
||||||
|
|
||||||
$players = [];
|
$players = [];
|
||||||
if($query !== false and $query !== true){
|
if($query !== false and $query !== true){
|
||||||
while(($d = $query->fetchArray(SQLITE3_ASSOC)) !== false){
|
while(($d = $query->fetchArray(SQLITE3_ASSOC)) !== false){
|
||||||
|
|
@ -308,7 +311,9 @@ class PlayerAPI{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if($alike === true){
|
if($alike === true){
|
||||||
$query = $this->server->query("SELECT ip,port,name FROM players WHERE name LIKE '$name%';"); //try getting player with non-full name match if none was found
|
$this->server->preparedSQL->player->getLike->reset();
|
||||||
|
$query = $this->server->preparedSQL->player->getLike->bindValue(":name", "$name%");
|
||||||
|
$query = $this->server->preparedSQL->player->getLike->execute(); //try getting player with non-full name match if none was found
|
||||||
if($query !== false and $query !== true){
|
if($query !== false and $query !== true){
|
||||||
while(($d = $query->fetchArray(SQLITE3_ASSOC)) !== false){
|
while(($d = $query->fetchArray(SQLITE3_ASSOC)) !== false){
|
||||||
$CID = PocketMinecraftServer::clientID($d["ip"], $d["port"]);
|
$CID = PocketMinecraftServer::clientID($d["ip"], $d["port"]);
|
||||||
|
|
|
||||||
|
|
@ -157,6 +157,8 @@ class PocketMinecraftServer{
|
||||||
public function startDatabase(){
|
public function startDatabase(){
|
||||||
$this->preparedSQL = new stdClass();
|
$this->preparedSQL = new stdClass();
|
||||||
$this->preparedSQL->entity = new stdClass();
|
$this->preparedSQL->entity = new stdClass();
|
||||||
|
$this->preparedSQL->player = new stdClass();
|
||||||
|
|
||||||
$this->database = new SQLite3(":memory:");
|
$this->database = new SQLite3(":memory:");
|
||||||
$this->query("PRAGMA journal_mode = OFF;");
|
$this->query("PRAGMA journal_mode = OFF;");
|
||||||
$this->query("PRAGMA encoding = \"UTF-8\";");
|
$this->query("PRAGMA encoding = \"UTF-8\";");
|
||||||
|
|
@ -173,6 +175,10 @@ class PocketMinecraftServer{
|
||||||
$this->preparedSQL->updateAction = $this->database->prepare("UPDATE actions SET last = :time WHERE ID = :id;");
|
$this->preparedSQL->updateAction = $this->database->prepare("UPDATE actions SET last = :time WHERE ID = :id;");
|
||||||
$this->preparedSQL->entity->setPosition = $this->database->prepare("UPDATE entities SET x = :x, y = :y, z = :z, pitch = :pitch, yaw = :yaw WHERE EID = :eid ;");
|
$this->preparedSQL->entity->setPosition = $this->database->prepare("UPDATE entities SET x = :x, y = :y, z = :z, pitch = :pitch, yaw = :yaw WHERE EID = :eid ;");
|
||||||
$this->preparedSQL->entity->setLevel = $this->database->prepare("UPDATE entities SET level = :level WHERE EID = :eid ;");
|
$this->preparedSQL->entity->setLevel = $this->database->prepare("UPDATE entities SET level = :level WHERE EID = :eid ;");
|
||||||
|
|
||||||
|
$this->preparedSQL->player->getEq = $this->database->prepare("SELECT ip,port,name FROM players WHERE name = :name;"); //'$name'
|
||||||
|
$this->preparedSQL->player->getLike = $this->database->prepare("SELECT ip,port,name FROM players WHERE name LIKE :name;"); //'$name'
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function query($sql, $fetch = false){
|
public function query($sql, $fetch = false){
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue