123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912 |
- <?php
- # ***** BEGIN LICENSE BLOCK *****
- # Version: MPL 1.1/GPL 2.0/LGPL 2.1
- #
- # The contents of this file are subject to the Mozilla Public License Version
- # 1.1 (the "License"); you may not use this file except in compliance with
- # the License. You may obtain a copy of the License at
- # http://www.mozilla.org/MPL/
- #
- # Software distributed under the License is distributed on an "AS IS" basis,
- # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- # for the specific language governing rights and limitations under the
- # License.
- #
- # The Original Code is Weave Basic Object Server
- #
- # The Initial Developer of the Original Code is
- # Mozilla Labs.
- # Portions created by the Initial Developer are Copyright (C) 2008
- # the Initial Developer. All Rights Reserved.
- #
- # Contributor(s):
- # Toby Elliott (telliott@mozilla.com)
- # balu
- # Daniel Triendl <daniel@pew.cc>
- # Mark Straver <moonchild@palemoon.org>
- #
- # Alternatively, the contents of this file may be used under the terms of
- # either the GNU General Public License Version 2 or later (the "GPL"), or
- # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- # in which case the provisions of the GPL or the LGPL are applicable instead
- # of those above. If you wish to allow use of your version of this file only
- # under the terms of either the GPL or the LGPL, and not to allow others to
- # use your version of this file under the terms of the MPL, indicate your
- # decision by deleting the provisions above and replace them with the notice
- # and other provisions required by the GPL or the LGPL. If you do not delete
- # the provisions above, a recipient may use your version of this file under
- # the terms of any one of the MPL, the GPL or the LGPL.
- #
- # ***** END LICENSE BLOCK *****
- require_once 'weave_basic_object.php';
- require_once 'weave_utils.php';
- require_once 'settings.php';
- class WeaveStorage
- {
- private $_username;
- private $_dbh;
- function __construct($username)
- {
- $this->_username = $username;
- log_error("Initalizing DB connecion!");
- try
- {
- if ( ! MYSQL_ENABLE )
- {
- $path = explode('/', $_SERVER['SCRIPT_FILENAME']);
- $db_name = SQLITE_FILE;
- array_pop($path);
- array_push($path, $db_name);
- $db_name = implode('/', $path);
- if ( ! file_exists($db_name) )
- {
- log_error("The required sqllite database is not present! $db_name");
- }
- log_error("Starting SQLite connection");
- $this->_dbh = new PDO('sqlite:' . $db_name);
- $this->_dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- }
- else if ( MYSQL_ENABLE )
- {
- log_error("Starting MySQL connection");
- $this->_dbh = new PDO("mysql:host=". MYSQL_HOST .";dbname=". MYSQL_DB, MYSQL_USER, MYSQL_PASSWORD);
- }
- }
- catch( PDOException $exception )
- {
- log_error("database unavailable " . $exception->getMessage());
- throw new Exception("Database unavailable " . $exception->getMessage() , 503);
- }
- }
- function get_connection()
- {
- return $this->_dbh;
- }
- function begin_transaction()
- {
- try
- {
- $this->_dbh->beginTransaction();
- }
- catch( PDOException $exception )
- {
- error_log("begin_transaction: " . $exception->getMessage());
- throw new Exception("Database unavailable", 503);
- }
- return 1;
- }
- function commit_transaction()
- {
- $this->_dbh->commit();
- return 1;
- }
- function get_max_timestamp($collection)
- {
- if (!$collection)
- {
- return 0;
- }
- try
- {
- $select_stmt = 'select max(modified) from wbo where username = :username and collection = :collection';
- $sth = $this->_dbh->prepare($select_stmt);
- $sth->bindParam(':username', $this->_username);
- $sth->bindParam(':collection', $collection);
- $sth->execute();
- }
- catch( PDOException $exception )
- {
- error_log("get_max_timestamp: " . $exception->getMessage());
- throw new Exception("Database unavailable", 503);
- }
- $result = $sth->fetchColumn();
- return round((float)$result, 2);
- }
- function get_collection_list()
- {
- try
- {
- $select_stmt = 'select distinct(collection) from wbo where username = :username';
- $sth = $this->_dbh->prepare($select_stmt);
- $sth->bindParam(':username', $this->_username);
- $sth->execute();
- }
- catch( PDOException $exception )
- {
- error_log("get_collection_list: " . $exception->getMessage());
- throw new Exception("Database unavailable", 503);
- }
- $collections = array();
- while ($result = $sth->fetchColumn())
- {
- $collections[] = $result;
- }
- return $collections;
- }
- function get_collection_list_with_timestamps()
- {
- try
- {
- $select_stmt = 'select collection, max(modified) as timestamp from wbo where username = :username group by collection';
- $sth = $this->_dbh->prepare($select_stmt);
- $sth->bindParam(':username', $this->_username);
- $sth->execute();
- }
- catch( PDOException $exception )
- {
- error_log("get_collection_list: " . $exception->getMessage());
- throw new Exception("Database unavailable", 503);
- }
- $collections = array();
- while ($result = $sth->fetch(PDO::FETCH_NUM))
- {
- $collections[$result[0]] = (float)$result[1];
- }
- return $collections;
- }
- function get_collection_list_with_counts()
- {
- try
- {
- $select_stmt = 'select collection, count(*) as ct from wbo where username = :username group by collection';
- $sth = $this->_dbh->prepare($select_stmt);
- $sth->bindParam(':username', $this->_username);
- $sth->execute();
- }
- catch( PDOException $exception )
- {
- error_log("get_collection_list_with_counts: " . $exception->getMessage());
- throw new Exception("Database unavailable", 503);
- }
- $collections = array();
- while ($result = $sth->fetch(PDO::FETCH_NUM))
- {
- $collections[$result[0]] = (int)$result[1];
- }
- return $collections;
- }
- function store_object(&$wbo)
- {
- try
- {
- if ( MYSQL_ENABLE )
- {
- $insert_stmt = 'insert into wbo (username, id, collection, parentid, predecessorid, sortindex, modified, payload, payload_size)
- values (:username, :id, :collection, :parentid, :predecessorid, :sortindex, :modified, :payload, :payload_size)
- on duplicate key update
- username=values(username), id=values(id), collection=values(collection), parentid=values(parentid),
- predecessorid=values(predecessorid), sortindex=values(sortindex), modified=values(modified), payload=values(payload),
- payload_size=values(payload_size)';
- }
- else
- {
- $insert_stmt = 'replace into wbo (username, id, collection, parentid, predecessorid, sortindex, modified, payload, payload_size)
- values (:username, :id, :collection, :parentid, :predecessorid, :sortindex, :modified, :payload, :payload_size)';
- }
-
- $sth = $this->_dbh->prepare($insert_stmt);
- $username = $this->_username;
- $id = $wbo->id();
- $collection = $wbo->collection();
- $parentid = $wbo->parentid();
- $predecessorid = $wbo->predecessorid();
- $sortindex = $wbo->sortindex();
- $modified = $wbo->modified();
- $payload = $wbo->payload();
- $payload_size = $wbo->payload_size();
- $sth->bindParam(':username', $username);
- $sth->bindParam(':id', $id);
- $sth->bindParam(':collection', $collection);
- $sth->bindParam(':parentid', $parentid);
- $sth->bindParam(':predecessorid', $predecessorid);
- $sth->bindParam(':sortindex', $sortindex);
- $sth->bindParam(':modified', $modified);
- $sth->bindParam(':payload', $payload);
- $sth->bindParam(':payload_size', $payload_size);
- $sth->execute();
- }
- catch( PDOException $exception )
- {
- error_log("store_object: " . $exception->getMessage());
- throw new Exception("Database unavailable", 503);
- }
- return 1;
- }
- function update_object(&$wbo)
- {
- $update = "update wbo set ";
- $params = array();
- $update_list = array();
- #make sure we have an id and collection. No point in continuing otherwise
- if (!$wbo->id() || !$wbo->collection())
- {
- error_log('Trying to update without a valid id or collection!');
- return 0;
- }
- if ($wbo->parentid_exists())
- {
- $update_list[] = "parentid = ?";
- $params[] = $wbo->parentid();
- }
- if ($wbo->predecessorid_exists())
- {
- $update_list[] = "predecessorid = ?";
- $params[] = $wbo->predecessorid();
- }
- if ($wbo->sortindex_exists())
- {
- $update_list[] = "sortindex = ?";
- $params[] = $wbo->sortindex();
- }
- if ($wbo->payload_exists())
- {
- $update_list[] = "payload = ?";
- $update_list[] = "payload_size = ?";
- $params[] = $wbo->payload();
- $params[] = $wbo->payload_size();
- }
- # Don't modify the timestamp on a non-payload/non-parent change change
- if ($wbo->parentid_exists() || $wbo->payload_exists())
- {
- #better make sure we have a modified date. Should have been handled earlier
- if (!$wbo->modified_exists())
- {
- error_log("Called update_object with no defined timestamp. Please check");
- $wbo->modified(microtime(1));
- }
- $update_list[] = "modified = ?";
- $params[] = $wbo->modified();
- }
- if (count($params) == 0)
- {
- return 0;
- }
- $update .= join($update_list, ",");
- $update .= " where username = ? and collection = ? and id = ?";
- $params[] = $this->_username;
- $params[] = $wbo->collection();
- $params[] = $wbo->id();
- try
- {
- $sth = $this->_dbh->prepare($update);
- $sth->execute($params);
- }
- catch( PDOException $exception )
- {
- error_log("update_object: " . $exception->getMessage());
- throw new Exception("Database unavailable", 503);
- }
- return 1;
- }
- function delete_object($collection, $id)
- {
- try
- {
- $delete_stmt = 'delete from wbo where username = :username and collection = :collection and id = :id';
- $sth = $this->_dbh->prepare($delete_stmt);
- $username = $this->_username;
- $sth->bindParam(':username', $username);
- $sth->bindParam(':collection', $collection);
- $sth->bindParam(':id', $id);
- $sth->execute();
- }
- catch( PDOException $exception )
- {
- error_log("delete_object: " . $exception->getMessage());
- throw new Exception("Database unavailable", 503);
- }
- return 1;
- }
- function delete_objects($collection, $id = null, $parentid = null, $predecessorid = null, $newer = null,
- $older = null, $sort = null, $limit = null, $offset = null, $ids = null,
- $index_above = null, $index_below = null)
- {
- $params = array();
- $select_stmt = '';
- if ($limit || $offset || $sort)
- {
- #sqlite can't do sort or limit deletes without special compiled versions
- #so, we need to grab the set, then delete it manually.
- $params = $this->retrieve_objects($collection, $id, 0, 0, $parentid, $predecessorid, $newer, $older, $sort, $limit, $offset, $ids, $index_above, $index_below);
- if (!count($params))
- {
- return 1; #nothing to delete
- }
- $paramqs = array();
- $select_stmt = "delete from wbo where username = ? and collection = ? and id in (" . join(", ", array_pad($paramqs, count($params), '?')) . ")";
- array_unshift($params, $collection);
- array_unshift($params, $username);
- }
- else
- {
- $select_stmt = "delete from wbo where username = ? and collection = ?";
- $params[] = $this->_username;
- $params[] = $collection;
- if ($id)
- {
- $select_stmt .= " and id = ?";
- $params[] = $id;
- }
- if ($ids && count($ids) > 0)
- {
- $qmarks = array();
- $select_stmt .= " and id in (";
- foreach ($ids as $temp)
- {
- $params[] = $temp;
- $qmarks[] = '?';
- }
- $select_stmt .= implode(",", $qmarks);
- $select_stmt .= ')';
- }
- if ($parentid)
- {
- $select_stmt .= " and parentid = ?";
- $params[] = $parentid;
- }
- if ($predecessorid)
- {
- $select_stmt .= " and predecessorid = ?";
- $params[] = $parentid;
- }
- if ($index_above)
- {
- $select_stmt .= " and sortindex > ?";
- $params[] = $parentid;
- }
- if ($index_below)
- {
- $select_stmt .= " and sortindex < ?";
- $params[] = $parentid;
- }
- if ($newer)
- {
- $select_stmt .= " and modified > ?";
- $params[] = $newer;
- }
- if ($older)
- {
- $select_stmt .= " and modified < ?";
- $params[] = $older;
- }
- if ($sort == 'index')
- {
- $select_stmt .= " order by sortindex desc";
- }
- else if ($sort == 'newest')
- {
- $select_stmt .= " order by modified desc";
- }
- else if ($sort == 'oldest')
- {
- $select_stmt .= " order by modified";
- }
- }
- try
- {
- $sth = $this->_dbh->prepare($select_stmt);
- $sth->execute($params);
- }
- catch( PDOException $exception )
- {
- error_log("delete_objects: " . $exception->getMessage());
- throw new Exception("Database unavailable", 503);
- }
- return 1;
- }
- function retrieve_object($collection, $id)
- {
- try
- {
- $select_stmt = 'select * from wbo where username = :username and collection = :collection and id = :id';
- $sth = $this->_dbh->prepare($select_stmt);
- $username = $this->_username;
- $sth->bindParam(':username', $username);
- $sth->bindParam(':collection', $collection);
- $sth->bindParam(':id', $id);
- $sth->execute();
- }
- catch( PDOException $exception )
- {
- error_log("retrieve_object: " . $exception->getMessage());
- throw new Exception("Database unavailable", 503);
- }
- $result = $sth->fetch(PDO::FETCH_ASSOC);
- $wbo = new wbo();
- $wbo->populate($result);
- return $wbo;
- }
- function retrieve_objects($collection, $id = null, $full = null, $direct_output = null, $parentid = null,
- $predecessorid = null, $newer = null, $older = null, $sort = null,
- $limit = null, $offset = null, $ids = null,
- $index_above = null, $index_below = null)
- {
- $full_list = $full ? '*' : 'id';
- $select_stmt = "select $full_list from wbo where username = ? and collection = ?";
- $params[] = $this->_username;
- $params[] = $collection;
- if ($id)
- {
- $select_stmt .= " and id = ?";
- $params[] = $id;
- }
- if ($ids && count($ids) > 0)
- {
- $qmarks = array();
- $select_stmt .= " and id in (";
- foreach ($ids as $temp)
- {
- $params[] = $temp;
- $qmarks[] = '?';
- }
- $select_stmt .= implode(",", $qmarks);
- $select_stmt .= ')';
- }
- if ($parentid)
- {
- $select_stmt .= " and parentid = ?";
- $params[] = $parentid;
- }
- if ($predecessorid)
- {
- $select_stmt .= " and predecessorid = ?";
- $params[] = $predecessorid;
- }
- if ($index_above)
- {
- $select_stmt .= " and sortindex > ?";
- $params[] = $parentid;
- }
- if ($index_below)
- {
- $select_stmt .= " and sortindex < ?";
- $params[] = $parentid;
- }
- if ($newer)
- {
- $select_stmt .= " and modified > ?";
- $params[] = $newer;
- }
- if ($older)
- {
- $select_stmt .= " and modified < ?";
- $params[] = $older;
- }
- if ($sort == 'index')
- {
- $select_stmt .= " order by sortindex desc";
- }
- else if ($sort == 'newest')
- {
- $select_stmt .= " order by modified desc";
- }
- else if ($sort == 'oldest')
- {
- $select_stmt .= " order by modified";
- }
- if ($limit)
- {
- $select_stmt .= " limit " . intval($limit);
- if ($offset)
- {
- $select_stmt .= " offset " . intval($offset);
- }
- }
- try
- {
- $sth = $this->_dbh->prepare($select_stmt);
- $sth->execute($params);
- }
- catch( PDOException $exception )
- {
- error_log("retrieve_collection: " . $exception->getMessage());
- throw new Exception("Database unavailable", 503);
- }
- if ($direct_output)
- return $direct_output->output($sth);
- $ids = array();
- while ($result = $sth->fetch(PDO::FETCH_ASSOC))
- {
- if ($full)
- {
- $wbo = new wbo();
- $wbo->populate($result);
- $ids[] = $wbo;
- }
- else
- $ids[] = $result{'id'};
- }
- return $ids;
- }
- function get_storage_total()
- {
- $username = $this->_username;
- $time = time();
-
- try
- {
- $select_stmt = 'select quota_usage, usage_time from users where username = :username';
- $sth = $this->_dbh->prepare($select_stmt);
- $sth->bindParam(':username', $username);
- $sth->execute();
- }
- catch( PDOException $exception )
- {
- error_log("get_storage_total (user field): " . $exception->getMessage());
- throw new Exception("Database unavailable", 503);
- }
- $result = $sth->fetch(PDO::FETCH_ASSOC);
- if ($result['quota_usage'] != NULL &&
- $result['usage_time'] != NULL &&
- ((int)$result['quota_usage'] != 0) &&
- ($time - (int)$result['usage_time'] < QUOTA_TTL) &&
- ((int)$result['quota_usage'] < MINQUOTA)) {
- # We have a usage size and it's recent enough and not close to the limit; use cached value
- return (int)$result['quota_usage'];
- }
- else
- {
- # We don't have a current cached value. Retrieve and store.
- try
- {
- $select_stmt = 'select round(sum(length(payload))/1024) from wbo where username = :username';
- $sth = $this->_dbh->prepare($select_stmt);
- $sth->bindParam(':username', $username);
- $sth->execute();
- }
- catch( PDOException $exception )
- {
- error_log("get_storage_total: " . $exception->getMessage());
- throw new Exception("Database unavailable", 503);
- }
- $usage = (int)$sth->fetchColumn();
- try
- {
- $update_stmt = 'update users set quota_usage = :usage, usage_time = :usage_time where username = :username';
- $sth = $this->_dbh->prepare($update_stmt);
- $sth->bindParam(':username', $username);
- $sth->bindParam(':usage', $usage);
- $sth->bindParam(':usage_time', $time);
- // error_log("Store query: update users set quota_usage = ".$usage.", usage_time = ".$time." where username = ".$username);
- $sth->execute();
- }
- catch( PDOException $exception )
- {
- error_log("get_storage_total (store): " . $exception->getMessage());
- throw new Exception("Database unavailable", 503);
- }
- return $usage;
- }
- }
- function get_collection_storage_totals()
- {
- try
- {
- $select_stmt = 'select collection, sum(payload_size) from wbo where username = :username group by collection';
- $sth = $this->_dbh->prepare($select_stmt);
- $username = $this->_username;
- $sth->bindParam(':username', $username);
- $sth->execute();
- }
- catch( PDOException $exception )
- {
- error_log("get_storage_total (" . $this->connection_details_string() . "): " . $exception->getMessage());
- throw new Exception("Database unavailable", 503);
- }
- $results = $sth->fetchAll(PDO::FETCH_NUM);
- $sth->closeCursor();
- $collections = array();
- foreach ($results as $result)
- {
- $collections[$result[0]] = (int)$result[1];
- }
- return $collections;
- }
- function get_user_quota()
- {
- return null;
- }
- function delete_storage($username)
- {
- log_error("delete storage");
- if (!$username)
- {
- throw new Exception("3", 404);
- }
- try
- {
- $delete_stmt = 'delete from wbo where username = :username';
- $sth = $this->_dbh->prepare($delete_stmt);
- $sth->bindParam(':username', $username);
- $sth->execute();
- $sth->closeCursor();
- }
- catch( PDOException $exception )
- {
- error_log("delete_user: " . $exception->getMessage());
- return 0;
- }
- return 1;
- }
- function delete_user($username)
- {
- log_error("delete User");
- if (!$username)
- {
- throw new Exception("3", 404);
- }
- try
- {
- $delete_stmt = 'delete from users where username = :username';
- $sth = $this->_dbh->prepare($delete_stmt);
- $sth->bindParam(':username', $username);
- $sth->execute();
- $sth->closeCursor();
- $delete_wbo_stmt = 'delete from wbo where username = :username';
- $sth = $this->_dbh->prepare($delete_wbo_stmt);
- $sth->bindParam(':username', $username);
- $sth->execute();
- }
- catch( PDOException $exception )
- {
- error_log("delete_user: " . $exception->getMessage());
- return 0;
- }
- return 1;
- }
-
- function store_user_login($username)
- {
- try
- {
- $update_statement = "update users set login = :logintime where username = :username";
- $time = time();
- $sth = $this->_dbh->prepare($update_statement);
- $sth->bindParam(':username', $username);
- $sth->bindParam(':logintime', $time);
- $sth->execute();
- }
- catch( PDOException $exception )
- {
- log_error("update login:" . $exception->getMessage());
- return 0;
- }
- return 1;
- }
- function clear_quota_usage($username)
- {
- try
- {
- $update_statement = "update users set quota_usage = 0 where username = :username";
- $sth = $this->_dbh->prepare($update_statement);
- $sth->bindParam(':username', $username);
- $sth->execute();
- }
- catch( PDOException $exception )
- {
- log_error("clear quota usage:" . $exception->getMessage());
- return 0;
- }
- return 1;
- }
-
- function create_user($username, $password)
- {
- log_error("Create User - Username: ".$username."|".$password);
- try
- {
- $create_statement = "insert into users (username, md5, login, quota_usage, usage_time)
- values (:username, :md5, null, 0, 0)";
- $sth = $this->_dbh->prepare($create_statement);
- $hash = WeaveHashFactory::factory();
- $password = $hash->hash($password);
- $sth->bindParam(':username', $username);
- $sth->bindParam(':md5', $password);
- $sth->execute();
- }
- catch( PDOException $exception )
- {
- log_error("create_user:" . $exception->getMessage());
- error_log("create_user:" . $exception->getMessage());
- return 0;
- }
- return 1;
- }
- function change_password($hash)
- {
- try
- {
- $update_statement = "update users set md5 = :md5 where username = :username";
- $sth = $this->_dbh->prepare($update_statement);
- $sth->bindParam(':username', $this->_username);
- $sth->bindParam(':md5', $hash);
- $sth->execute();
- }
- catch( PDOException $exception )
- {
- log_error("change_password:" . $exception->getMessage());
- return 0;
- }
- return 1;
- }
- #function checks if user exists
- function exists_user()
- {
- try
- {
- $select_stmt = 'select username from users where username = :username';
- $sth = $this->_dbh->prepare($select_stmt);
- $username = $this->_username;
- $sth->bindParam(':username', $username);
- $sth->execute();
- }
- catch( PDOException $exception )
- {
- error_log("exists_user: " . $exception->getMessage());
- throw new Exception("Database unavailable", 503);
- }
- if (!$result = $sth->fetch(PDO::FETCH_ASSOC))
- {
- return null;
- }
- return 1;
- }
- function get_password_hash()
- {
- log_error("auth-user: " . $this->_username);
- try
- {
- $select_stmt = 'select md5 from users where username = :username';
- $sth = $this->_dbh->prepare($select_stmt);
- $username = $this->_username;
- $sth->bindParam(':username', $username);
- $sth->execute();
- }
- catch( PDOException $exception )
- {
- error_log("get_password_hash: " . $exception->getMessage());
- throw new Exception("Database unavailable", 503);
- }
- $result = $sth->fetchColumn();
- if ($result === FALSE) $result = "";
-
- return $result;
- }
- }
- ?>
|