php-mpos/public/include/classes/setting.class.php
Sebastian Grewe f67e63b6fc [REFACTOR] Refactored classes for error handling
* [ADDED] More error codes
* [MODIFIED] Class updates to use Base Class all the time
* [MODIFIED] Cronjobs have been slightly adjusted
* [ADDED] More base class features
2013-11-05 14:34:31 +01:00

42 lines
1.2 KiB
PHP

<?php
// Make sure we are called from index.php
if (!defined('SECURITY')) die('Hacking attempt');
class Setting extends Base {
protected $table = 'settings';
/**
* Fetch a value from our table
* @param name string Setting name
* @return value string Value
**/
public function getValue($name) {
$stmt = $this->mysqli->prepare("SELECT value FROM $this->table WHERE name = ? LIMIT 1");
if ($this->checkStmt($stmt) && $stmt->bind_param('s', $name) && $stmt->execute() && $result = $stmt->get_result())
return $result->fetch_object()->value;
return $this->sqlError();
}
/**
* Insert or update a setting
* @param name string Name of the variable
* @param value string Variable value
* @return bool
**/
public function setValue($name, $value) {
$stmt = $this->mysqli->prepare("
INSERT INTO $this->table (name, value)
VALUES (?, ?)
ON DUPLICATE KEY UPDATE value = ?");
if ($stmt && $stmt->bind_param('sss', $name, $value, $value) && $stmt->execute())
return true;
return $this->sqlError();
}
}
$setting = new Setting($debug, $mysqli);
$setting->setDebug($debug);
$setting->setMysql($mysqli);
$setting->setErrorCodes($aErrorCodes);