function getQuorum($index, $token, $hits, $offset, $limit) { if (Util::tryEmpty($token)) { return array(); } Util::isEmpty("index", $index); $sql = sprintf("select id from %s where match('", $index); $sql .= '\\"' . $token . '\\"\\/' . $hits . "')"; $sql .= sprintf(" limit %d,%d ", $offset, $limit); $rows = MySQL\Helper::fetchRows($this->connx, $sql); $ids = array(); foreach ($rows as $row) { array_push($ids, $row["id"]); } return $ids; }
static function create($loginId, $name, $seoName, $hash, $bin_hash, $strItemsJson, $postId, $dl_bit) { try { //input check settype($loginId, "integer"); settype($postId, "integer"); Util::isEmpty("name", $name); Util::isEmpty("md5 hash of name", $hash); Util::isEmpty("md5 bin hash of name", $bin_hash); //list // op_bit is offline_processing bit - set to zero on create $sql1 = "insert into sc_list (login_id,name, seo_name,md5_name, bin_md5_name, "; $sql1 .= "items_json, version, op_bit , created_on, pseudo_id, dl_bit) "; $sql1 .= " values(:login_id,:name,:seo_name,:hash,:bin_hash, "; $sql1 .= " :items_json, 1 , 0, now(), :pseudo_id, :dl_bit) "; $dbh = PDOWrapper::getHandle(); // *** Tx start *** $dbh->beginTransaction(); $stmt = $dbh->prepare($sql1); $stmt->bindParam(":login_id", $loginId); $stmt->bindParam(":name", $name); $stmt->bindParam(":seo_name", $seoName); $stmt->bindParam(":hash", $hash); $stmt->bindParam(":bin_hash", $bin_hash); $stmt->bindParam(":items_json", $strItemsJson); //set pseudo_id to NULL explicitly $stmt->bindValue(":pseudo_id", null, \PDO::PARAM_STR); $stmt->bindParam(":dl_bit", $dl_bit); $stmt->execute(); $stmt = NULL; $listId = $dbh->lastInsertId(); settype($listId, "integer"); // list:item relationships $sql2 = "insert into sc_list_item(list_id, item_id) values (%d,%d)"; $sql2 = sprintf($sql2, $listId, $postId); $dbh->exec($sql2); // update item_count + pseudo_id of list $pseudoId = PseudoId::encode($listId); $sql3 = " update sc_list set item_count = 1, pseudo_id = :pseudo_id "; $sql3 .= " where id = :list_id "; $stmt3 = $dbh->prepare($sql3); $stmt3->bindParam(":list_id", $listId); $stmt3->bindParam(":pseudo_id", $pseudoId); $stmt3->execute(); $stmt3 = NULL; // *** Tx end *** $dbh->commit(); $dbh = null; return $listId; } catch (\PDOException $e) { $dbh->rollBack(); $dbh = null; throw new DBException($e->getMessage(), $e->getCode()); } catch (\Exception $ex) { $dbh->rollBack(); $dbh = null; throw new DBException($ex->getMessage(), $ex->getCode()); } }
static function changePassword($tableName, $loginId, $email, $password) { if (empty($tableName)) { trigger_error("User Table name is not supplied", E_USER_ERROR); exit(1); } Util::isEmpty('Email', $email); Util::isEmpty('Password', $password); $mysqli = MySQL\Connection::getInstance()->getHandle(); // get random salt $salt = substr(md5(uniqid(rand(), true)), 0, 8); $password = trim($password); $message = $password . $salt; //create SHA-1 digest from email and password // we store this digest in table $digest = sha1($message); $sql = " update {table} set updated_on=now(), salt=?, password=? where email = ? and login_id = ?"; $sql = str_replace("{table}", $tableName, $sql); $stmt = $mysqli->prepare($sql); if ($stmt) { $stmt->bind_param("sssi", $salt, $digest, $email, $loginId); $stmt->execute(); $stmt->close(); } else { MySQL\Error::handle($mysqli); } }