try
!group set <GROUPNAME> <PLAYERNAME|PID>
try
!group set <GROUPNAME> <PLAYERNAME|PID>
which game? CoD4? CoD4 1.8x?
can you send us your error?
maybe this one http://php.net/manual/de/function.mb-strtolower.php ?
you could use my chatlog plugin and modify the php file
https://gitlab.mirko-rosenthal.info/gsm-plugins/chatlog
just add
<PLAYER_PBGUID>
and
$this->players[$guid]->getPBGuid()
change this line
%PHP% -f gsm.php -- -game %GAME% -cfgdir %CFGDIR% -logdir %LOGDIR%
to this
%PHP% -f gsm.php -- -game %GAME% -cfgdir %CFGDIR% -logdir %LOGDIR% -debug 127
in the gsm.bat
can you post the full gsm log?
The only thing we "spam" is the "New Version available" Notification each 15 Minutes.
And you can disable the rconSay Message for it via config in the daemon section (updatecheck = false)
can you check if the mysql connection works over the console? Maybe it's a permission problem in the database?
"databasetype": "mysqli",
replace the mysqli with mysql
Hi, short update. I think it's possible.
I'm working on a plugin and I hope that I've a first beta version today
EDIT1:
can you check if this works for you:
atm. not, but I can try to look in the codx server files and reimplement it in GSM
You can't block perks via GSManager.
You would need a CoD4 Mod to disable them
the logfile says that everything is fine.
Atm. I've no idea why the config is empty. If the file would be write protected you would get a Warning Log entry.
Which PHP Version do you use?
Hi,
is the users.json completely empty?
Can you send us the logfiles?
Yep haven't seen the edit
Short question: is voting enabled on the server?
Hi,
sry for the long waiting time.
Can you try to replace the content of the plugins/randommapcycle/randommapcycle.php file with this one:
<?php
/**
* GSManager
*
* This is a mighty and platform independent software for administrating game servers of various kinds.
* If you need help with installing or using this software, please visit our website at: www.gsmanager.de
* If you have licensing enquiries e.g. related to commercial use, please contact us at: sales@gsmanager.de
*
* @copyright Greenfield Concept UG (haftungsbeschränkt)
* @license GSManager EULA <https://www.gsmanager.de/eula.php>
* @version 1.2.1
**/
namespace GSM\Plugins\Randommapcycle;
use GSM\Daemon\Core\Utils;
/**
* randommapcycle Class
*
* The randommapcycle plugin
*
*/
class RandomMapCycle extends Utils {
/**
* Maps
*
* @var array $maps Maps
*/
private $maps = array();
/**
* lastmaps
*
* @var array $lastmaps the last maps
*/
private $lastmaps = array();
/**
* Chosen
*
* @var array $chosen
*/
private $chosen = array();
/**
* Start
*
* @var int $start
*/
private $start = 0;
/**
* last announce
*
* @var int $lastannounce
*/
private $lastAnnounce = 0;
/**
* vote in progress
*
* @var boolean $voteinprogress
*/
private $voteinprogress = false;
/**
* Skips
*
* @var array $skips
*/
private $skips = array();
/**
* Gametypes
*
* @var array $gametypes
*/
private $gametypes = array();
/**
* Voters
*
* @var array $voters
*/
private $voters = array();
/**
* Votes
*
* @var array $votes
*/
private $votes = array();
private $job_id;
/**
* Inits the plugin
*
* This function initiates the plugin. This means that it register commands
* default values, and events. It's important that every plugin has this function
* Otherwise the plugin exists but can't be used
*/
public function initPlugin() {
parent::initPlugin();
$this->config->setDefault('randommapcycle', 'enabled', true);
$this->config->setDefault('randommapcycle', 'type', 2);
$this->config->setDefault('randommapcycle', 'mapcount', 3);
$this->config->setDefault('randommapcycle', 'duration', 300);
$this->config->setDefault('randommapcycle', 'interval', 90);
$this->config->setDefault('randommapcycle', 'maps', array('*'));
$this->config->setDefault('randommapcycle', 'gametypes', array('*'));
$this->config->setDefault('randommapcycle', 'ignorepriorgametype', true);
$this->config->setDefault('randommapcycle', 'ignorepriormaps', 3);
$this->config->setDefault('randommapcycle', 'skipquorum', '50%');
$this->config->setDefault('randommapcycle', 'skipvoting', false);
}
/**
* Function to enable this plugin
*/
public function enable() {
parent::enable();
$this->events->register('nextMap', [$this, 'eventNextMap']);
/* Fix if the vote command isn't enabled */
if ($this->commands->getCommand('vote') === false) {
$this->commands->register('vote', false, false, $this);
}
$this->commands->registerSubCommand('vote', 'choice', '~choice \d+~i', [$this, 'commandVmap']);
$this->commands->registerSubCommand('vote', 'skip', false, [$this, 'commandSkip']);
$this->readConfig();
list($this->lastmaps[]) = $this->mod->getLastMaps(1);
$this->eventNextMap();
}
/**
* Function to disable this plugin
*/
public function disable() {
parent::disable();
$this->events->unregister('nextMap', [$this, 'eventNextMap']);
$this->commands->unregisterSubCommand('vote', 'choice');
$this->commands->unregisterSubCommand('vote', 'skip');
}
/**
* executes the readConfig event.
*/
private function readConfig() {
$this->maps = array();
$allowed_maps = $this->config->get('randommapcycle', 'maps');
if (is_array($allowed_maps) && isset($allowed_maps[0]) && $allowed_maps[0] == '*') {
$this->maps = $this->mod->getMaps();
} elseif (is_array($allowed_maps)) {
$this->maps = $allowed_maps;
}
$allowed_gametypes = $this->config->get('randommapcycle', 'gametypes');
if (is_array($allowed_gametypes) && isset($allowed_gametypes[0]) && $allowed_gametypes[0] == '*') {
$this->gametypes = $this->mod->getGametypes();
} elseif (is_array($allowed_gametypes)) {
$this->gametypes = $allowed_gametypes;
}
}
/**
* executes the nextMap event.
*/
public function eventNextMap() {
$this->readConfig();
$lastmaps = $this->mod->getLastMaps(2);
if ($lastmaps[1] == $lastmaps[0]) {
return;
}
$this->lastmaps[] = $lastmaps[0];
$this->voteinprogress = false;
$last_map_count = count($this->lastmaps);
/** Shift to old entrys */
while ($last_map_count > $this->config->get('randommapcycle', 'ignorepriormaps')) {
array_shift($this->lastmaps);
}
$this->lastmaps = array_merge($this->lastmaps);
if ($this->config->get('randommapcycle', 'type') == 2) {
$this->logging->debug("[Random MapCycle] Random map set.");
$this->jobs->addSingleJob(20, array($this, "setRandomMap"));
}
if ($this->config->get('randommapcycle', 'type') == 1) {
$this->jobs->addSingleJob(20, array($this, "startVote"));
}
}
/**
* announce if the vote is possible to skip.
*/
public function setRandomMap() {
$this->readConfig();
$this->chooseMap(1);
if (empty($this->chosen)) {
return false;
}
$this->rcon->rconSetNextMap($this->chosen[0]['map'], $this->chosen[0]['gametype'], false);
$this->skips = array();
if ($this->config->get('randommapcycle', 'skipvoting')) {
$this->announceSkipMessage();
}
}
/**
* the message on the server for the skip vote.
*/
public function announceSkipMessage() {
$this->rcon->rconSay($this->language->get('randommapcycle.voteforskip', array('<MAP>', '<GAMETYPE>'), array($this->mod->getLongMapName($this->chosen[0]['map']), $this->mod->getLongGametype($this->chosen[0]['gametype']))));
$this->job_id = $this->jobs->addSingleJob($this->config->get('randommapcycle', 'interval'), array($this, 'announceSkipMessage'));
}
/**
* execztes the command skip.
*
* @param string $guid Guid of executing player
* @param string[] $parameters The chatline splitted by " " without !command
*/
public function commandSkip($guid, $parameters) {
if ($this->config->get('randommapcycle', 'type') != 2 || !$this->config->get('randommapcycle', 'skipvoting')) {
return;
}
if (in_array($guid, $this->skips)) {
$this->players[$guid]->say($this->language->get('randommapcycle.alreadyvoted'));
} else {
$this->skips[] = $guid;
if (substr(trim($this->config->get('randommapcycle', 'skipquorum')), -1) == '%') {
$needed = round(((int) $this->config->get('randommapcycle', 'skipquorum')) / 100 * count($this->players));
} else {
$needed = (int) $this->config->get('randommapcycle', 'skipquorum');
}
$skippers = count($this->skips);
$search = array('<SKIPPERS>', '<NEEDED>', '<MAP>', '<GAMETYPE>');
$replace = array($skippers, $needed, $this->mod->getLongMapName($this->chosen[0]['map']), $this->mod->getLongGametype($this->chosen[0]['gametype']));
$say = $this->language->get('randommapcycle.votedskip', $search, $replace);
$this->rcon->rconSay($say);
if ($skippers >= $needed) {
$this->jobs->deleteJob($this->job_id);
$this->setRandomMap();
}
}
}
/**
* choose a map
*
* @param int $count
*/
private function chooseMap($count) {
$maps = $this->maps;
$gametypes = $this->gametypes;
foreach ($maps as $key => $value) {
if (in_array($value, $this->lastmaps)) {
unset($maps[$key]);
}
}
if ($this->config->get('randommapcycle', 'ignorepriorgametype')) {
$current = $this->mod->getCurrentGametype();
foreach ($gametypes as $key => $value) {
if ($value == $current) {
unset($gametypes[$key]);
}
}
}
$gametypes = array_merge($gametypes);
if (count($gametypes) == 0) {
$gametypes[0] = $this->mod->getCurrentGametype();
}
if (count($maps) < $count) {
/* @todo logmarker */
$this->logging->warning("[Random MapCycle] Couldn't choose a random map because count(maps) < $count");
return false;
}
$this->chosen = array();
for ($i = 1; $i <= $count; $i++) {
$maps = array_merge($maps);
$rand = rand(0, count($maps) - 1);
if ($this->mod->getEngine() == 'frostbite3') {
// $this->rcon->getMaps()->clear();
$map_gametypes = $this->rcon->getMaps()->getAllowedGametypesOnMap($maps[$rand]);
foreach ($gametypes as $key => $value) {
if (!in_array($value, $map_gametypes)) {
unset($gametypes[$key]);
}
}
$gametypes = array_merge($gametypes);
}
$rand2 = rand(0, count($gametypes) - 1);
$this->chosen[] = array('map' => $maps[$rand], 'gametype' => $gametypes[$rand2]);
unset($maps[$rand]);
}
return true;
}
/**
* Ends a Vote
*/
public function endVote() {
$this->voteinprogress = false;
arsort($this->votes);
reset($this->votes);
$won = key($this->votes);
$this->rcon->rconSay($this->language->get('randommapcycle.wonvote', array('<MAP>', '<GAMETYPE>'), array($this->mod->getLongMapName($this->chosen[$won]['map']), $this->mod->getLongGametype($this->chosen[$won]['gametype']))));
$this->rcon->rconSetNextMap($this->chosen[$won]['map'], $this->chosen[$won]['gametype'], false);
$this->jobs->deleteJob($this->job_id);
}
/**
* Starts a Vote
*/
public function startVote() {
$this->chooseMap($this->config->get('randommapcycle', 'mapcount'));
$this->start = time();
$this->voteinprogress = true;
$this->votes = array_fill(0, $this->config->get('randommapcycle', 'mapcount'), 0);
$this->voters = array();
$this->announceVote();
$this->jobs->addSingleJob($this->config->get('randommapcycle', 'duration'), array($this, "endVote"));
}
/**
* Announces a Vote
*/
public function announceVote() {
$mapstr = array();
foreach ($this->chosen as $id => $map) {
$mapstr[] = $this->language->get('randommapcycle.list', array('<ID>', '<MAP>', '<GAMETYPE>'), array($id + 1, $this->mod->getLongMapName($map['map']), $this->mod->getLongGametype($map['gametype'])));
}
$mapstr = implode("\n", $mapstr);
$this->rcon->rconSay($this->language->get('randommapcycle.voteformap') . "\n" . $mapstr);
$this->job_id = $this->jobs->addSingleJob($this->config->get('randommapcycle', 'interval'), array($this, "announceVote"));
}
/**
* executes the command vmap
*
* Example: !vmap 1-3
*
* @param string $guid Guid of executing player
* @param string[] $parameters The chatline splitted by " " without !command
*/
public function commandVmap($guid, $parameters) {
if ($this->config->get('randommapcycle', 'type') != 1) {
return;
}
if (!$this->voteinprogress) {
return;
}
//-1 because we start with 1 but count array with 0
$map = $parameters[0] - 1;
if (!array_key_exists($map, $this->chosen)) {
return;
}
if (in_array($guid, $this->voters)) {
return;
}
$this->voters[] = $guid;
$this->votes[$map] ++;
$str = $this->language->get('randommapcycle.voted', array('<MAP>', '<GAMETYPE>'), array($this->mod->getLongMapName($this->chosen[$map]['map']), $this->mod->getLongGametype($this->chosen[$map]['gametype'])));
$this->players[$guid]->say($str);
}
}
Display More
it seems that the weapon restrictions for CoD5 are buggy. I'll try to fix this
can you try to replace the daemon/libraries/database/database.php file with
<?php
/**
* GSManager
*
* This is a mighty and platform independent software for administrating game servers of various kinds.
* If you need help with installing or using this software, please visit our website at: www.gsmanager.de
* If you have licensing enquiries e.g. related to commercial use, please contact us at: sales@gsmanager.de
*
* @copyright Greenfield Concept UG (haftungsbeschränkt)
* @license GSManager EULA <https://www.gsmanager.de/eula.php>
* @version 1.2.1
**/
namespace GSM\Daemon\Libraries\Database;
use \PDO;
use GSM\Daemon\Libraries\Logging\LogLevel;
/**
* Database Class
*
* This class is a powerfull class to handle your database connection
* through PDO as database driver it#s possible to use nearly every database
* This class also supports transactions with rollbacks
*
* @author Mirko911 <mirko911@gsmanager.de>
*/
class Database {
/**
* Database handler
* @var PDO
*/
protected $dbh;
/**
* Value of the last inserted id
*
* @var int
*/
protected $last_inserted_id;
/**
* How to order the get sql query
*
* @var string
*/
protected $order;
/**
* How to limit the get sql query
* @var string
*/
protected $limit;
/**
*
* PDO Statement
*
* @var PDOStatement
*/
protected $sth;
/**
* The database prefix
*
* For example gsm_
*
* @var string
*/
protected $prefix;
/**
* Fetch type for database
* @var type
*/
protected $fetch_type;
/**
* Saves the parameters for PDO
*
* @var array
*/
protected $options = array(
PDO::ATTR_PERSISTENT => true,
PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ,
PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8",
);
/**
* Set Parameters for PDO
*
* @link http://is1.php.net/manual/en/pdo.setattribute.php List of Paramters
*
* @param array $options Key => $value where both are PDO Constatns
*/
public function setParameters($options) {
foreach ($options as $key => $value) {
$this->options[$key] = $value;
}
}
/**
* Set Prefix for Tables
*
* Every Table gets this pfx | except you use the query/exec function
*
* @param string $prefix
*/
public function setPrefix($prefix) {
$this->prefix = $prefix;
}
/**
* Sets the fetch type for 1 query
*
* @see http://www.php.net/manual/de/pdostatement.fetch.php
* @param int $type Pdo fetch type
*/
public function setFetchType($type) {
$this->fetch_type = $type;
}
/**
* Returns the Prefix
*
* @return string
*/
public function getPrefix() {
return $this->prefix;
}
/**
* Constrcutor function
*
* @link http://www.php.net/manual/de/pdo.drivers.php List of drivers you can use
* @param string $dsn Data Source Name
* @param string $user Username [optional]
* @param string $password Password [optional]
*/
public function __construct($dsn, $user = '', $password = '') {
$this->connect($dsn, $user, $password);
}
/**
* Desturctor
*/
public function __destruct() {
$this->dbh = null;
}
/**
* Returns a string if object is printed
*
* Notice: all plugins which where moved to core needs a __tostring function
* to get it working with the permissions system. Therefore the return of __tostring must me the
* namespace like deamon, punishment, permissions ...
*
* @see http://php.net/manual/en/language.oop5.magic.php#object.tostring
* @return string
*/
public function __toString() {
return 'database';
}
/**
* Connects to Database
*
* @param string $dsn Data Source Name
* @param string $user Username if needed, otherwise it's an empty string
* @param string $password Password if needed, otherwise it's an empty string
*/
public function connect($dsn, $user, $password) {
$this->dbh = null;
try {
$this->dbh = new PDO($dsn, $user, $password, $this->options);
} catch (\PDOException $ex) {
\GSM\Daemon\Core\Registry::getInstance()->logging->error('Database Class: ' . $ex);
}
}
/**
* Binds a value to a predefined parameter
*
* With this function it's possible to execute a query multiple
* times with different values
*
* @param string $name Parameter Name
* @param mixed $value Parameter Value
* @param int $type PDO Param Type [optional]
*/
public function bindValue($name, $value, $type = NULL) {
if (is_null($type)) {
$type = $this->getPDOType($value);
}
$this->sth->bindValue($name, $value, $type);
}
/**
* Adds a specific order for the get function
*
* you can use this function multiple times to set multiple orders
*
* @param string $column Name of the column
* @param string $type ASC or DESC
* @return Database The actual instance of the database class
*/
public function addOrder($column, $type = '') {
if (empty($this->order)) {
$this->order = ' ORDER by ';
}
$this->order .= '`' . $column . '`' . ' ' . $type;
return $this;
}
/**
* Removes the order, so it can't affect the next query
*/
public function clearOrder() {
$this->order = '';
}
/**
* Sets a limit for the get function
*
* @param int $startvalue ID to start from
* @param int $count How much results to you want to get?
* @return Database The actual instance of the database class
*/
public function setLimit($startvalue, $count) {
$this->limit = ' LIMIT ' . $startvalue . ',' . $count;
return $this;
}
/**
* Removes the limit, so it can't affect the next query
*/
public function clearLimit() {
$this->limit = '';
}
/**
* Gets Values from the database
*
* If you pass an array as input you can directly affect the where clause
* Example:
* $db->get("gsm_users", array("id",5)); => "SELECT * FROM gsm_users WHERE id = 5
*
* If you only need some fields you can pass a numeric array with the fields you want
* Example:
* $db->get("gsm_users", array("id",5), array("guid", "lastseen")); => "SELECT guid,lastseen FROM gsm_users WHERE id = 5
*
* If you pass a string as input, you'll pass a sql query
* Example:
* $db->get("gsm_users", "SELECT * FROM <TABLE> WHERE guid = :guid, array(":guid" => $guid));
* For SQL Querys it's possible to use the placeholders <TABLE> for table with prefix or <PFX> for prefix
*
* The functions setOrder and setLimit will affect BOTH types
*
* @param string $table Name of the table without prefix
* @param string|string[] $input Key => $value array or string with query
* @param array $parameters Optional Parameters for BindValue or to select columns, depends on $input
* @return array SQL Result. Default Data is access able like an obj $player->guid
*/
public function get($table, $input = array(), $parameters = array()) {
if (is_array($input)) {
if (!empty($parameters)) {
if (is_array($parameters)) {
$params = implode(',', $parameters);
} else {
$params = $parameters;
}
$sql = 'SELECT ' . $params . ' FROM ' . $this->prefix . $table . ' WHERE 1';
} else {
$sql = 'SELECT * FROM ' . $this->prefix . $table . ' WHERE 1';
}
foreach ($input as $key => $value) {
$sql .= ' AND `' . $key . '` = :col_' . $key;
}
$sql = rtrim($sql, ',');
$sql .= $this->order;
$sql .= $this->limit;
$this->sth = $this->dbh->prepare($sql);
foreach ($input as $key => $value) {
$this->bindValue(':col_' . $key, $value);
}
} else if (is_string($input)) {
$sql = str_replace(array("<PFX>", "<TABLE>"), array($this->prefix, $this->prefix . $table), $input);
$this->sth = $this->dbh->prepare($sql);
foreach ($parameters as $key => $value) {
$this->bindValue($key, $value);
}
}
$this->sth->execute();
$this->clearLimit();
$this->clearOrder();
if (!is_numeric($this->fetch_type)) {
$data = $this->sth->fetchAll();
} else {
$data = $this->sth->fetchAll($this->fetch_type);
$this->fetch_type = NULL;
}
\GSM\Daemon\Core\Registry::getInstance()->logging->debug("SQL: $sql Code: " . $this->dbh->errorCode(), LogLevel::DEBUG_DATABASE);
return $data;
}
/**
* Gets the first result from a database
*
* If you pass an array as input you can directly affect the where clause
* Example:
* $db->get("gsm_users", array("id",5)); => "SELECT * FROM gsm_users WHERE id = 5
*
* If you only need some fields you can pass a numeric array with the fields you want
* Example:
* $db->get("gsm_users", array("id",5), array("guid", "lastseen")); => "SELECT guid,lastseen FROM gsm_users WHERE id = 5
*
* If you pass a string as input, you'll pass a sql query
* Example:
* $db->get("gsm_users", "SELECT * FROM <TABLE> WHERE guid = :guid, array(":guid" => $guid));
* For SQL Query it's possible to use the placeholders <TABLE> for table with prefix or <PFX> for prefix
*
* The functions setOrder and setLimit will affect BOTH types
*
* @param string $table Name of the table without prefix
* @param string|string[] $input Key => $value array or string with query
* @param array $parameters Optional Parameters for BindValue or to select columns, depends on $input
* @return array SQL Result. Default Data is access able like an obj $player->guid
*/
public function row($table, $input = array(), $parameters = array()) {
$this->setLimit(0, 1);
$result = $this->get($table, $input, $parameters);
if (is_array($result) && !empty($result)) {
return $result[0];
} elseif (empty($result)) {
return false;
} else {
return $result;
}
}
/**
* Upddates a database entry
*
* @param string $table Name of the table without prefix
* @param array $entrys Key Value Array
* @param array $condition_or_statement Array with 3 Entrys 1)Column Name 2) Condition 3) Value Example | or SQL Statement
* @return int affected rows
*/
public function update($table, $entrys, $condition_or_statement) {
$sql = 'UPDATE ' . $this->prefix . $table;
$sql .= ' SET ';
foreach ($entrys as $key => $value) {
$sql .= '`' . $key . '` = :col_' . $key . ',';
}
$sql = rtrim($sql, ',');
if (is_array($condition_or_statement)) {
if (!is_int($condition_or_statement[2]) && !is_bool($condition_or_statement[2])) {
$condition_or_statement[2] = '"' . $condition_or_statement[2] . '"';
}
$sql .= ' WHERE `' . $condition_or_statement[0] . '` ' . $condition_or_statement[1] . ' ' . $condition_or_statement[2];
} else {
$sql .= ' WHERE ' . $condition_or_statement;
}
$this->sth = $this->dbh->prepare($sql);
foreach ($entrys as $key => $value) {
$this->bindValue(':col_' . $key, $value);
}
$this->sth->execute();
\GSM\Daemon\Core\Registry::getInstance()->logging->debug("SQL: $sql Code: " . $this->dbh->errorCode(), LogLevel::DEBUG_DATABASE);
return $this->sth->rowCount();
}
/**
* Insert new data into the database
*
* @param string $table Name of the table without prefix
* @param array $entrys $key => $value where key is the column name
* @return boolean True if successful else false
*/
public function insert($table, $entrys) {
$sql = 'INSERT INTO ' . $this->prefix . $table;
$sql .= ' (' . implode(',', array_map(function($val) { return '`' . $val . '`'; }, array_keys($entrys)));
$sql .= ') VALUES (';
foreach ($entrys as $key => $value) {
$sql .= ':col_' . $key . ',';
}
$sql = rtrim($sql, ',');
$sql .= ')';
$this->sth = $this->dbh->prepare($sql);
foreach ($entrys as $key => $value) {
$this->bindValue(':col_' . $key, $value);
}
\GSM\Daemon\Core\Registry::getInstance()->logging->debug("SQL: $sql", LogLevel::DEBUG_DATABASE);
if (!$this->sth->execute()) {
return false;
} else {
return true;
}
}
/**
* Deletes an entry from Database
*
* @param string $table Name of the table without prefix
* @param string $column_or_statement Name of the column | or own SQL Statement
* @param mixed $value Value to sarch for in the overgiven column
* @return int affected rows
*/
public function delete($table, $column_or_statement, $value = false) {
$sql = 'DELETE FROM ' . $this->prefix . $table;
if ($value !== false) {
$sql .= ' WHERE ' . '`' . $column_or_statement . '`';
$sql .= ' = ';
if (!is_int($value) && !is_bool($value)) {
$value = '"' . $value . '"';
}
$sql .= $value;
} else {
$sql .= " WHERE " . $column_or_statement;
}
\GSM\Daemon\Core\Registry::getInstance()->logging->debug("SQL: $sql", LogLevel::DEBUG_DATABASE);
return $this->dbh->exec($sql);
}
/**
* Returns the last inserted id or NULL
*
* @return int
*/
public function getLastInsertedId() {
return $this->dbh->lastInsertId();
}
/**
* Direclty query the database
*
* @param string $sql The sql query
*
* @return \PDOStatement The Result
*/
public function query($sql) {
$sql = str_replace('<PFX>', $this->prefix, $sql);
\GSM\Daemon\Core\Registry::getInstance()->logging->debug("SQL: $sql", LogLevel::DEBUG_DATABASE);
return $this->dbh->query($sql);
}
/**
* Executes a query
*
* @param string $sql The sql query
*
* @return int Affected Rows
*/
public function exec($sql) {
$sql = str_replace('<PFX>', $this->prefix, $sql);
\GSM\Daemon\Core\Registry::getInstance()->logging->debug("SQL: $sql", LogLevel::DEBUG_DATABASE);
return $this->dbh->exec($sql);
}
/**
* Prepare SQL Statement
* @param string $sql The sql query
*/
public function prepare($sql) {
$sql = str_replace('<PFX>', $this->prefix, $sql);
\GSM\Daemon\Core\Registry::getInstance()->logging->debug("SQL: $sql", LogLevel::DEBUG_DATABASE);
$this->sth = $this->dbh->prepare($sql);
}
/**
* Executes a statement
*
* @return \PDOStatement The Result
*/
public function execute() {
return $this->sth->execute();
}
/**
* Fetches the Data after a statement
* @param int $mode
* @return mixed depends on the mode
*/
public function fetch($mode) {
return $this->sth->fetch($mode);
}
/**
* Start a transaction
*
* It's possible to execute multiple querys and commit them
*
* @return boolean
*/
public function beginTransaction() {
return $this->dbh->beginTransaction();
}
/**
* Ends a transaction
*
* It's possible to execute multiple querys and commit them
*
* @return boolean
*/
public function endTransaction() {
return $this->dbh->commit();
}
/**
* Cancel a transaction
*
* It's possible to execute multiple querys and commit them
*
* @return boolean
*/
public function cancelTransaction() {
return $this->dbh->rollBack();
}
/**
* Finds the fitting PDO Typoe for a parameter
* @param mixed $param string bool or int
* @return int
*/
private function getPDOType($param) {
if (is_string($param)) {
return PDO::PARAM_STR;
} elseif (is_int($param)) {
return PDO::PARAM_INT;
} elseif (is_bool($param)) {
return PDO::PARAM_BOOL;
} else {
return PDO::PARAM_STR;
}
}
/**
* Replaces any parameter placeholders in a query with the value of that
* parameter. Useful for debugging. Assumes anonymous parameters from
* $params are are in the same order as specified in $query
*
* @param string $query The sql query with parameter placeholders
* @param array $params The array of substitution parameters
* @return string The interpolated query
*/
public function interpolateQuery($query, $params) {
$keys = array();
# build a regular expression for each parameter
foreach ($params as $key => $value) {
if (is_string($key)) {
$keys[] = '/:' . $key . '/';
} else {
$keys[] = '/[?]/';
}
}
$query = preg_replace($keys, $params, $query, 1, $count);
#trigger_error('replaced '.$count.' keys');
return $query;
}
}
Display More