本文整理汇总了PHP中SplFixedArray::key方法的典型用法代码示例。如果您正苦于以下问题:PHP SplFixedArray::key方法的具体用法?PHP SplFixedArray::key怎么用?PHP SplFixedArray::key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SplFixedArray
的用法示例。
在下文中一共展示了SplFixedArray::key方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getFavoriteByTweetId
/**
* gets the Favorite by tweet it id
*
* @param \PDO $pdo PDO connection object
* @param int $tweetId tweet id to search for
* @return \SplFixedArray array of Favorites found or null if not found
* @throws \PDOException when mySQL related errors occur
* @throws \TypeError when variables are not the correct data type
**/
public static function getFavoriteByTweetId(\PDO $pdo, int $tweetId)
{
// sanitize the tweet id
$tweetId = filter_var($tweetId, FILTER_VALIDATE_INT);
if ($tweetId <= 0) {
throw new \PDOException("tweet id is not positive");
}
// create query template
$query = "SELECT profileId, tweetId, favoriteDate FROM favorite WHERE tweetId = :tweetId";
$statement = $pdo->prepare($query);
// bind the member variables to the place holders in the template
$parameters = ["tweetId" => $tweetId];
$statement->execute($parameters);
// build an array of favorites
$favorites = new \SplFixedArray($statement->rowCount());
$statement->setFetchMode(\PDO::FETCH_ASSOC);
while (($row = $statement->fetch()) !== false) {
try {
$favorite = new Favorite($row["tweetId"], $row["profileId"], $row["favoriteDate"]);
$favorites[$favorites->key()] = $favorite;
$favorites->next();
} catch (\Exception $exception) {
// if the row couldn't be converted, rethrow it
throw new \PDOException($exception->getMessage(), 0, $exception);
}
}
return $favorites;
}
示例2: storeSQLResultsInArray
/**
* function to store multiple database results into an SplFixedArray
*
* @param PDOStatement $statement pdo statement object
* @return SPLFixedArray all message obtained from database
* @throws PDOException if mySQL related errors occur
*/
public static function storeSQLResultsInArray(PDOStatement $statement)
{
//build an array of messages, as an SPLFixedArray object
//set the size of the object to the number of retrieved rows
$retrievedMessages = new SplFixedArray($statement->rowCount());
$statement->setFetchMode(PDO::FETCH_ASSOC);
//while rows can still be retrieved from the result
while (($row = $statement->fetch()) !== false) {
try {
$message = new Message($row["messageId"], $row["listingId"], $row["orgId"], $row["messageText"]);
//place result in the current field, then advance the key
$retrievedMessages[$retrievedMessages->key()] = $message;
$retrievedMessages->next();
} catch (Exception $exception) {
//rethrow the exception if retrieval failed
throw new PDOException($exception->getMessage(), 0, $exception);
}
}
return $retrievedMessages;
}
示例3: SplFixedArray
<?php
$array = new SplFixedArray(3);
$array[0] = "Hello";
$array[1] = "world";
$array[2] = "elePHPant";
foreach ($array as $value) {
echo $array->key(array("this", "should", "not", "execute"));
}
示例4: getAllImages
/**
* getAllImages
*
* @param \PDO $pdo PDO connection object
* @return \SplFixedArray SplFixedArray of images found or null if not found
* @throws \PDOException when mySQL related errors occur
* @throws \TypeError when variables are not the correct data type
**/
public static function getAllImages(\PDO $pdo)
{
// create query template
$query = "SELECT imageId, imageProfileId, imageFileName, imageType FROM image";
$statement = $pdo->prepare($query);
$statement->execute();
// build an array of images
$images = new \SplFixedArray($statement->rowCount());
$statement->setFetchMode(\PDO::FETCH_ASSOC);
while (($row = $statement->fetch()) !== false) {
try {
$image = new Image($row["imageId"], $row["imageProfileId"], $row["imageFileName"], $row["imageType"]);
$images[$images->key()] = $image;
$images->next();
} catch (\Exception $exception) {
// if the row couldn't be converted, rethrow it
throw new \PDOException($exception->getMessage(), 0, $exception);
}
}
return $images;
}
示例5: getAllRatings
/**
* gets all ratings
*
* @param PDO $pdo PDO connection object
* @return SplFixedArray all ratings found
* @throws PDOException when mySQL errors occur
*/
public static function getAllRatings(PDO $pdo)
{
//create query template
$query = "select trailId, userId, rating FROM rating";
$statement = $pdo->prepare($query);
$statement->execute();
// build an array of rating values
$ratings = new SplFixedArray($statement->rowCount());
$statement->setFetchMode(PDO::FETCH_ASSOC);
while (($row = $statement->fetch()) !== false) {
try {
$rating = new Rating($row["userId"], $row["trailId"], $row["ratingValue"]);
$ratings[$ratings->key()] = $rating;
$ratings->next();
} catch (Exception $exception) {
// if the row couldn't be converted rethrow it
throw new PDOException($exception->getMessage(), 0, $exception);
}
}
return $ratings;
}
示例6: key
public function key()
{
echo "A::key\n";
return parent::key();
}
示例7: getSegmentBySegmentStopElevation
/**
* gets segment by segmentStopElevation
*
* @param PDO $pdo pointer to PDO connection
* @param int $segmentStopElevation stop elevation to trail-search for
* @return mixed segment found or null if not found
* @throws PDOException when mySQL related errors occur
* @throws RangeException when range is invalid
* @throws Exception for other exception
*/
public static function getSegmentBySegmentStopElevation(PDO &$pdo, $segmentStopElevation)
{
//sanitize the int before searching
try {
$segmentStopElevation = Filter::filterInt($segmentStopElevation, "segment stop", false);
} catch (InvalidArgumentException $invalidArgument) {
throw new PDOException($invalidArgument->getMessage(), 0, $invalidArgument);
} catch (RangeException $range) {
throw new RangeException($range->getMessage(), 0, $range);
} catch (Exception $exception) {
throw new Exception($exception->getMessage(), 0, $exception);
}
//create query template
$query = "SELECT segmentId, ST_AsWKT(segmentStop) AS segmentStop, ST_AsWKT(segmentStart) AS segmentStart, segmentStartElevation, segmentStopElevation FROM segment WHERE segmentStopElevation = :segmentStopElevation";
$statement = $pdo->prepare($query);
//binds segmentStopElevation to placeholder
$parameters = array("segmentStopElevation" => $segmentStopElevation);
$statement->execute($parameters);
//build an array of segments
$segments = new SplFixedArray($statement->rowCount());
$statement->setFetchMode(PDO::FETCH_ASSOC);
while (($row = $statement->fetch()) !== false) {
try {
$segmentStartJSON = Gisconverter::wktToGeojson($row["segmentStart"]);
$segmentStopJSON = Gisconverter::wktToGeojson($row["segmentStop"]);
$segmentStartGenericObject = json_decode($segmentStartJSON);
$segmentStopGenericObject = json_decode($segmentStopJSON);
$segmentStart = new Point($segmentStartGenericObject->coordinates[0], $segmentStartGenericObject->coordinates[1]);
$segmentStop = new Point($segmentStopGenericObject->coordinates[0], $segmentStopGenericObject->coordinates[1]);
$segment = new Segment($row["segmentId"], $segmentStart, $segmentStop, $row["segmentStartElevation"], $row["segmentStopElevation"]);
$segments[$segments->key()] = $segment;
$segments->next();
} catch (Exception $e) {
//if the row couldn't be converter, rethrow it
throw new PDOException($e->getMessage(), 0, $e);
}
}
return $segments;
}
示例8: getAllTweets
/**
* gets all Tweets
*
* @param PDO $pdo pointer to PDO connection, by reference
* @return mixed SplFixedArray of Tweets found or null if not found
* @throws PDOException when mySQL related errors occur
**/
public static function getAllTweets(PDO &$pdo)
{
// create query template
$query = "SELECT tweetId, profileId, tweetContent, tweetDate FROM tweet";
$statement = $pdo->prepare($query);
$statement->execute();
// build an array of tweets
$tweets = new SplFixedArray($statement->rowCount());
$statement->setFetchMode(PDO::FETCH_ASSOC);
while (($row = $statement->fetch()) !== false) {
try {
$tweet = new Tweet($row["tweetId"], $row["profileId"], $row["tweetContent"], $row["tweetDate"]);
$tweets[$tweets->key()] = $tweet;
$tweets->next();
} catch (Exception $exception) {
// if the row couldn't be converted, rethrow it
throw new PDOException($exception->getMessage(), 0, $exception);
}
}
// count the results in the array and return:
// 1) null if 0 results
// 2) the entire array if >= 1 result
$numberOfTweets = count($tweets);
if ($numberOfTweets === 0) {
return null;
} else {
return $tweets;
}
}
示例9: getAllListingTypes
/**
* retrieves all listingtypes
*
* @param PDO $pdo pdo connection object
* @return SplFixedArray all organizations
* @throws PDOException if mySQL errors occur
*/
public static function getAllListingTypes(PDO $pdo)
{
//create query template and execute
$query = "SELECT listingTypeId, listingType FROM listingType";
$statement = $pdo->prepare($query);
$statement->execute();
//build an array of the retrieved results
//set the size of the object to the number of retrieved rows
$retrievedTypes = new SplFixedArray($statement->rowCount());
$statement->setFetchMode(PDO::FETCH_ASSOC);
//while rows can still be retrieved from the result
while (($row = $statement->fetch()) !== false) {
try {
$listingType = new ListingType($row["listingTypeId"], $row["listingType"]);
//place result in the current field, then advance the key
$retrievedTypes[$retrievedTypes->key()] = $listingType;
$retrievedTypes->next();
} catch (Exception $exception) {
//rethrow the exception if retrieval failed
throw new PDOException($exception->getMessage(), 0, $exception);
}
}
return $retrievedTypes;
}
示例10: getAllProductLocations
/**
* gets all ProductLocations
*
* @param PDO $pdo pointer to PDO connection, by reference
* @return SplFixedArray all productLocations found
* @throws PDOException when mySQL related errors occur
**/
public static function getAllProductLocations(PDO &$pdo)
{
// create query template
$query = "SELECT locationId, productId, unitId, quantity FROM productLocation";
$statement = $pdo->prepare($query);
$statement->execute();
// build an array of ProductLocation(s)
$productLocations = new SplFixedArray($statement->rowCount());
$statement->setFetchMode(PDO::FETCH_ASSOC);
while (($row = $statement->fetch()) !== false) {
try {
$productLocation = new ProductLocation($row["locationId"], $row["productId"], $row["unitId"], $row["quantity"]);
$productLocations[$productLocations->key()] = $productLocation;
$productLocations->next();
} catch (PDOException $exception) {
// if the row couldn't be converted, rethrow it
throw new PDOException($exception->getMessage(), 0, $exception);
}
}
return $productLocations;
}
示例11: getAllGame
/**
* gets all Game
*
* @param \PDO $pdo PDO connection object
* @return \SplFixedArray SplFixedArray of Game found or null if not found
* @throws \PDOException when mySQL related errors occur
* @throws \TypeError when variables are not the correct data type
**/
public static function getAllGame(\PDO $pdo)
{
//create query template
$query = "SELECT gameId, gameFirstTeamId, gameSecondTeamId, gameTime FROM game ";
$statement = $pdo->prepare($query);
$statement->execute();
//build an array of game
$games = new \SplFixedArray($statement->rowCount());
$statement->setFetchMode(\PDO::FETCH_ASSOC);
while (($row = $statement->fetch()) !== false) {
try {
$game = new Game($row["gameId"], $row["gameFirstTeamId"], $row["gameSecondTeamId"], $row["gameTime"]);
$games[$games->key()] = $game;
$games->next();
} catch (\Exception $exception) {
// if the row couldn't be converted rethrow it
throw new \PDOException($exception->getMessage(), 0, $exception);
}
}
return $games;
}
示例12: getAllProfiles
public static function getAllProfiles(\PDO $pdo)
{
// Create query template and execute
$query = "SELECT profileId, profileAdmin, profileNameFirst, profileNameLast, profileEmail, profileUserName, profileSalt, profileHash, profileActivationToken FROM profile";
$statement = $pdo->prepare($query);
$statement->execute();
// Build an array of matches
$profiles = new \SplFixedArray($statement->rowCount());
$statement->setFetchMode(\PDO::FETCH_ASSOC);
while (($row = $statement->fetch()) !== false) {
try {
$profile = new Profile($row["profileId"], $row["profileAdmin"], $row["profileNameFirst"], $row["profileNameLast"], $row["profileEmail"], $row["profileUserName"], $row["profileSalt"], $row["profileHash"], $row["profileActivationToken"]);
$profiles[$profiles->key()] = $profile;
$profiles->next();
} catch (\Exception $exception) {
throw new \PDOException($exception->getMessage(), 0, $exception);
}
}
return $profiles;
}
示例13: getFollowerByFollowedId
/**
* gets the Follower relationship by the person being followed
*
* @param \PDO $pdo PDO connection object
* @param int $followerFollowedId the person being followed
* @return \SplFixedArray SplFixedArray of Follower relationships found or null if not found
* @throws \PDOException when mySQL related errors occur
* @throws \TypeError when variables are not the correct data type
**/
public static function getFollowerByFollowedId(\PDO $pdo, int $followerFollowedId)
{
//Sanitize the followed id
if ($followerFollowedId <= 0) {
throw new \PDOException("Get Follower by Followed: Followed Id is not positive");
}
//Create a query template
$query = "SELECT followerFollowerId, followerFollowedId FROM follower WHERE followerFollowedId = :followerFollowedId";
$statement = $pdo->prepare($query);
//Search based on the one being followed
$parameters = ["followerFollowedId" => $followerFollowedId];
$statement->execute($parameters);
//Build an array of follower relationships
$followers = new \SplFixedArray($statement->rowCount());
$statement->setFetchMode(\PDO::FETCH_ASSOC);
while (($row = $statement->fetch()) !== false) {
try {
$follower = new Follower($row["followerFollowerId"], $row["followerFollowedId"]);
$followers[$followers->key()] = $follower;
$followers->next();
} catch (\Exception $exception) {
//If the row couldn't be converted, rethrow it
throw new \PDOException($exception->getMessage(), 0, $exception);
}
}
return $followers;
}
示例14: getFavoriteTeamsByFavoriteTeamProfileId
/**
* gets the list of this profiles favorite teams
*
* @param \PDO $pdo connection object
* @param int $allFavoriteTeams search for
* @return \SplFixedArray SplFixedArray of all teams favorited found
* @throws \PDOException when db related errors occur
* @throws \TypeError when variables are not correct data type
**/
public static function getFavoriteTeamsByFavoriteTeamProfileId(\PDO $pdo, int $favoriteTeamProfileId)
{
// sanitize the favoriteTeamProfileId
if ($favoriteTeamProfileId <= 0) {
throw new \PDOException("that profile doesnt exist");
}
// create a query template
$query = "SELECT favoriteTeamProfileId, favoriteTeamTeamId FROM favoriteTeam WHERE favoriteTeamProfileId = :favoriteTeamProfileId";
$statement = $pdo->prepare($query);
// bind the favoriteTeamTeamId to the place holder in the template
$parameters = ["favoriteTeamProfileId" => $favoriteTeamProfileId];
$statement->execute($parameters);
// build an array of favorite teams
$favoriteTeams = new \SplFixedArray($statement->rowCount());
$statement->setFetchMode(\PDO::FETCH_ASSOC);
while (($row = $statement->fetch()) !== false) {
try {
$favoriteTeam = new FavoriteTeam($row["favoriteTeamProfileId"], $row["favoriteTeamTeamId"]);
$favoriteTeams[$favoriteTeams->key()] = $favoriteTeam;
$favoriteTeams->next();
} catch (\Exception $exception) {
// if the row can't be converted, rethrow it
throw new \PDOException($exception->getMessage(), 0, $exception);
}
}
return $favoriteTeams;
}
示例15: getTrailByTrailUuid
public static function getTrailByTrailUuid(PDO &$pdo, $trailUuid)
{
//sanitize the trailUuid before searching
try {
$trailUuid = Filter::filterString($trailUuid, "trailUuid");
} catch (InvalidArgumentException $invalidArgument) {
throw new PDOException($invalidArgument->getMessage(), 0, $invalidArgument);
} catch (RangeException $range) {
throw new PDOException($range->getMessage(), 0, $range);
} catch (Exception $exception) {
throw new PDOException($exception->getMessage(), 0, $exception);
}
//create query template
$query = "SELECT trailId, userId, browser, createDate, ipAddress, submitTrailId, trailAmenities, trailCondition,trailDescription, trailDifficulty, trailDistance, trailName, trailSubmissionType,\ntrailTerrain, trailTraffic, trailUse, trailUuid FROM trail WHERE trailUuid = :trailUuid";
$statement = $pdo->prepare($query);
//bind trailUuid to placeholder
$parameters = array("trailUuid" => $trailUuid);
$statement->execute($parameters);
//build an array of trails
$trails = new SplFixedArray($statement->rowCount());
$statement->setFetchMode(PDO::FETCH_ASSOC);
while (($row = $statement->fetch()) !== false) {
try {
//new trail ($trailId, $userId, $submitTrailId, $browser, $createDate, $ipAddress, $trailAccessibility, $trailAmenities, $trailCondition,$trailDescription, $trailDifficulty, $trailDistance, $trailSubmissionType,$trailTerrain, $trailName, $trailTraffic, $trailUse, $trailUuId)
$trail = new Trail($row["trailId"], $row["userId"], $row["browser"], $row["createDate"], $row["ipAddress"], $row["submitTrailId"], $row["trailAmenities"], $row["trailCondition"], $row["trailDescription"], $row["trailDifficulty"], $row["trailDistance"], $row["trailName"], $row["trailSubmissionType"], $row["trailTerrain"], $row["trailTraffic"], $row["trailUse"], $row["trailUuid"]);
$trails[$trails->key()] = $trail;
$trails->next();
} catch (Exception $e) {
//if the row couldn't be converted, rethrow it
throw new PDOException($e->getMessage(), 0, $e);
}
}
return $trails;
}