Skip to content

Commit

Permalink
Changed conf class to new db
Browse files Browse the repository at this point in the history
Issue #20

Also some whitespace fixes in database.inc.php
  • Loading branch information
jeroenrnl committed Jul 16, 2015
1 parent e162c95 commit 434b379
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
14 changes: 8 additions & 6 deletions php/classes/conf.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,12 @@ public function getId() {
*/
public static function loadFromDB() {
confDefault::getConfig();
$sql="SELECT conf_id, value FROM " . DB_PREFIX . "conf";
$qry=new select(array("co" => "conf"));
$qry->addFields(array("conf_id", "value"));

$result=query($sql, "Cannot load configuration from database");
$result=query($qry, "Cannot load configuration from database");

while($row= fetch_row($result)) {
while($row = fetch_row($result)) {
$key=$row[0];
$value=$row[1];
try {
Expand All @@ -74,9 +75,10 @@ public static function loadFromDB() {
/* An unknown item will automatically be deleted from the
database, so we can remove items without leaving a mess */
log::msg($e->getMessage(), log::NOTIFY, log::CONF);
$sql="DELETE FROM " . DB_PREFIX . "conf WHERE " .
"conf_id='" . escape_string($key) . "';";
query($sql);
$qry=new delete(array("co" => "conf"));
$qry->where(new clause("conf_id=:confid"));
$qry->addParam(new param(":confid", $key, PDO::PARAM_STR));
query($qry);
}

}
Expand Down
13 changes: 8 additions & 5 deletions php/database.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function query($sql, $error = false) {
log::msg($sql, log::NOTIFY, log::SQL);

// New DB
if($sql instanceof query) {
if ($sql instanceof query) {
return db::query($sql);
} else {

Expand Down Expand Up @@ -84,26 +84,29 @@ function num_rows($result) {
}

function fetch_row($result) {
if ($result instanceof PDOStatement) {
return $result->fetch(PDO::FETCH_NUM);
}
return mysql_fetch_row($result);
}

function fetch_array($result) {
if($result instanceof PDOStatement) {
if ($result instanceof PDOStatement) {
return $result->fetch(PDO::FETCH_ASSOC);
}
return mysql_fetch_array($result);
}

function fetch_assoc($result) {
if($result instanceof PDOStatement) {
if ($result instanceof PDOStatement) {
return $result->fetch(PDO::FETCH_ASSOC);
}
return mysql_fetch_assoc($result);
}


function free_result($result) {
if($result instanceof PDOStatement) {
if ($result instanceof PDOStatement) {
return $result->closeCursor();
}
return mysql_free_result($result);
Expand All @@ -115,7 +118,7 @@ function insert_id() {

function result($result, $row) {
// $row is never used
if($result instanceof PDOStatement) {
if ($result instanceof PDOStatement) {
return $result->fetch(PDO::FETCH_BOTH)[0];
}
return mysql_result($result, $row);
Expand Down

0 comments on commit 434b379

Please sign in to comment.