PDO compat

This commit is contained in:
Shish 2011-01-01 15:28:30 +00:00
parent 8b2e3262fe
commit 175ceac490
3 changed files with 19 additions and 22 deletions

View File

@ -175,7 +175,10 @@ class DatabaseConfig extends BaseConfig {
$this->values = $cached; $this->values = $cached;
} }
else { else {
$this->values = $this->database->db->query("SELECT name, value FROM config")->fetchAll(); $this->values = array();
foreach($this->database->get_all("SELECT name, value FROM config") as $row) {
$this->values[$row["name"]] = $row["value"];
}
$this->database->cache->set("config", $this->values); $this->database->cache->set("config", $this->values);
} }
} }
@ -190,8 +193,8 @@ class DatabaseConfig extends BaseConfig {
} }
} }
else { else {
$this->database->Execute("DELETE FROM config WHERE name = ?", array($name)); $this->database->Execute("DELETE FROM config WHERE name = :name", array("name"=>$name));
$this->database->Execute("INSERT INTO config VALUES (?, ?)", array($name, $this->values[$name])); $this->database->Execute("INSERT INTO config VALUES (:name, :value)", array("name"=>$name, "value"=>$this->values[$name]));
} }
$this->database->cache->delete("config"); $this->database->cache->delete("config");
} }

View File

@ -66,7 +66,7 @@ class Image {
assert(is_numeric($id)); assert(is_numeric($id));
global $database; global $database;
$image = null; $image = null;
$row = $database->get_row("SELECT * FROM images WHERE images.id=?", array($id)); $row = $database->get_row("SELECT * FROM images WHERE images.id=:id", array("id"=>$id));
return ($row ? new Image($row) : null); return ($row ? new Image($row) : null);
} }
@ -79,7 +79,7 @@ class Image {
assert(is_string($hash)); assert(is_string($hash));
global $database; global $database;
$image = null; $image = null;
$row = $database->db->GetRow("SELECT images.* FROM images WHERE hash=?", array($hash)); $row = $database->db->GetRow("SELECT images.* FROM images WHERE hash=:hash", array("hash"=>$hash));
return ($row ? new Image($row) : null); return ($row ? new Image($row) : null);
} }
@ -112,12 +112,11 @@ class Image {
if($limit < 1) $limit = 1; if($limit < 1) $limit = 1;
$querylet = Image::build_search_querylet($tags); $querylet = Image::build_search_querylet($tags);
$querylet->append(new Querylet("ORDER BY images.id DESC LIMIT ? OFFSET ?", array($limit, $start))); $querylet->append(new Querylet("ORDER BY images.id DESC LIMIT :limit OFFSET :offset", array("limit"=>$limit, "offset"=>$start)));
$result = $database->execute($querylet->sql, $querylet->variables); $result = $database->execute($querylet->sql, $querylet->variables);
while(!$result->EOF) { while($row = $result->fetch()) {
$images[] = new Image($result->fields); $images[] = new Image($row);
$result->MoveNext();
} }
return $images; return $images;
} }
@ -136,15 +135,15 @@ class Image {
#return $database->db->GetOne("SELECT COUNT(*) FROM images"); #return $database->db->GetOne("SELECT COUNT(*) FROM images");
$total = $database->cache->get("image-count"); $total = $database->cache->get("image-count");
if(!$total) { if(!$total) {
$total = $database->db->GetOne("SELECT COUNT(*) FROM images"); $total = $database->get_one("SELECT COUNT(*) FROM images");
$database->cache->set("image-count", $total, 600); $database->cache->set("image-count", $total, 600);
} }
return $total; return $total;
} }
else if(count($tags) == 1 && !preg_match("/[:=><]/", $tags[0])) { else if(count($tags) == 1 && !preg_match("/[:=><]/", $tags[0])) {
return $database->db->GetOne( return $database->get_one(
$database->engine->scoreql_to_sql("SELECT count FROM tags WHERE SCORE_STRNORM(tag) = SCORE_STRNORM(?)"), $database->engine->scoreql_to_sql("SELECT count FROM tags WHERE SCORE_STRNORM(tag) = SCORE_STRNORM(:tag)"),
$tags); array("tag"=>$tags[0]));
} }
else { else {
$querylet = Image::build_search_querylet($tags); $querylet = Image::build_search_querylet($tags);
@ -230,12 +229,7 @@ class Image {
if($cached) return $cached; if($cached) return $cached;
if(!isset($this->tag_array)) { if(!isset($this->tag_array)) {
$this->tag_array = Array(); $this->tag_array = $database->get_col("SELECT tag FROM image_tags JOIN tags ON image_tags.tag_id = tags.id WHERE image_id=:id ORDER BY tag", array("id"=>$this->id));
$row = $database->Execute("SELECT tag FROM image_tags JOIN tags ON image_tags.tag_id = tags.id WHERE image_id=? ORDER BY tag", array($this->id));
while(!$row->EOF) {
$this->tag_array[] = $row->fields['tag'];
$row->MoveNext();
}
} }
$database->cache->set("image-{$this->id}-tags", $this->tag_array); $database->cache->set("image-{$this->id}-tags", $this->tag_array);

View File

@ -41,12 +41,12 @@ class User {
public static function by_session($name, $session) { public static function by_session($name, $session) {
global $config, $database; global $config, $database;
if($database->engine->name == "mysql") { if($database->engine->name == "mysql") {
$query = "SELECT * FROM users WHERE name = ? AND md5(concat(pass, ?)) = ?"; $query = "SELECT * FROM users WHERE name = :name AND md5(concat(pass, :ip)) = :sess";
} }
else { else {
$query = "SELECT * FROM users WHERE name = ? AND md5(pass || ?) = ?"; $query = "SELECT * FROM users WHERE name = :name AND md5(pass || :ip) = :sess";
} }
$row = $database->get_row($query, array($name, get_session_ip($config), $session)); $row = $database->get_row($query, array("name"=>$name, "ip"=>get_session_ip($config), "sess"=>$session));
return is_null($row) ? null : new User($row); return is_null($row) ? null : new User($row);
} }