php-mpos/public/include/classes/setting.class.php
2014-01-28 07:26:08 -05:00

43 lines
1.3 KiB
PHP

<?php
$defflip = (!cfip()) ? exit(header('HTTP/1.1 401 Unauthorized')) : 1;
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())
if ($result->num_rows > 0)
return $result->fetch_object()->value;
// Log error but return empty string
$this->sqlError();
return "";
}
/**
* 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);