本文整理汇总了PHP中Connection::createConnection方法的典型用法代码示例。如果您正苦于以下问题:PHP Connection::createConnection方法的具体用法?PHP Connection::createConnection怎么用?PHP Connection::createConnection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Connection
的用法示例。
在下文中一共展示了Connection::createConnection方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getAllFriends
public function getAllFriends(User $user)
{
$con = Connection::createConnection();
$result = mysql_query("SELECT u1.id as user_id, u1.username as user_name, u2.* FROM user u1, userprofile u2 where u1.id = u2.id AND u1.id != {$user->id}");
$friendList = array();
while ($row = mysql_fetch_array($result)) {
$userProfile = new UserProfile();
$tempUser = new User();
//setting user
$tempUser->id = $row['user_id'];
$tempUser->username = $row['user_name'];
$userProfile->setUser($tempUser);
//Setting user profile
$userProfile->id = $row['id'];
$userProfile->age = $row['age'];
$userProfile->country = $row['country'];
$userProfile->favgame = $row['favgame'];
$userProfile->humour = $row['humour'];
$userProfile->imgurl = $row['imgurl'];
$userProfile->job = $row['job'];
$userProfile->language = $row['language'];
$userProfile->politicalview = $row['politicalview'];
$userProfile->religion = $row['religion'];
$userProfile->school = $row['school'];
array_push($friendList, $userProfile);
}
return $friendList;
}
示例2: sellArtifact
/**
*
* @param <Inventory> $inventory
* @param <int> $artifactPrice
* @param <GameProfile> $updatedGameProfile
* @return <Boolean>
* @SQL update gameprofile set gold = 100 where userid = 1
* @SQL delete from inventory where id=1 AND userid=1
*
*/
public function sellArtifact($inventory, $artifactPrice, $updatedGameProfile)
{
$con = Connection::createConnection();
$user = $updatedGameProfile->user;
$updateGameProfile = mysql_query("update gameprofile set gold = {$updatedGameProfile->gold} where userid = {$user->id}");
//delete from inventory
$deleteInventory = mysql_query("delete from inventory where id={$inventory->id} AND userid={$user->id}");
mysql_query("commit");
Connection::closeConnection($con);
return true;
}
示例3: addToInventory
/**
*
* @param <Inventory> $inventory
* @return <Inventory>
* @SQL Insert into inventory values (NULL,1,1,1)
*/
public function addToInventory($inventory)
{
$con = Connection::createConnection();
$artifact = $inventory->artifact;
$user = $inventory->user;
$result = mysql_query("Insert into inventory values (NULL,{$inventory->artifactLvl},{$artifact->id},{$user->id})");
$inventory->id = mysql_insert_id();
mysql_query("commit");
Connection::closeConnection($con);
return $inventory;
}
示例4: addSkill
/**
*
* @param <String> $columnName
* @param <GameProfile> $gameProfile
* @return <Boolean>
* @SQL update gameprofile set spylvl=spylvl+1 where globallvl > spylvl+scoutlvl+buylvl+sharelvl AND userid =1
*/
public function addSkill($columnName, $gameProfile)
{
$con = Connection::createConnection();
$user = $gameProfile->user;
$addPoints = mysql_query("update gameprofile set {$columnName}={$columnName}+1 where globallvl > spylvl+scoutlvl+buylvl+sharelvl AND userid ={$user->id}");
if (mysql_affected_rows() < 1) {
Connection::closeConnection($con);
return false;
} else {
return true;
}
}
示例5: isUsernameAvailable
/**
*
* @param <User> $username
* @return <User>
* @SQL Select * From user Where username = 1
*/
public function isUsernameAvailable($username)
{
$con = Connection::createConnection();
$result = mysql_query("Select * From user Where username = '{$username}'");
$loginid = -1;
$tempArray = mysql_fetch_array($result);
if (mysql_num_rows($result) == 1) {
$user = new User();
$user->id = $tempArray['id'];
$user->username = $tempArray['username'];
}
Connection::closeConnection($con);
return $user;
}
示例6: login
* @return JSON Information of the user.
*/
function login($conn)
{
$JSON = array();
$array_data = array();
// Gets the e-mail and password received from the login factory.
$email = $_REQUEST['email'];
$pass = $_REQUEST['pass'];
$query = "SELECT id, fullName, email, receipt, type FROM person WHERE email='{$email}' AND pass='{$pass}'";
$result = $conn->query($query);
while ($row = mysqli_fetch_array($result)) {
$array_data[] = $row;
}
foreach ($array_data as &$row) {
$JSON[] = array('id' => $row['id'], 'fullName' => utf8_encode($row['fullName']), 'email' => utf8_encode($row['email']), 'receipt' => $row['receipt'], 'type' => $row['type']);
}
if ($JSON == []) {
echo false;
} else {
echo json_encode($JSON);
}
}
// Try to make the connection with the database.
$connection = new Connection();
$conn = $connection->createConnection();
if ($conn) {
login($conn);
} else {
echo false;
}
示例7: getShareProgress
public function getShareProgress($gameProfile, $gameProgress)
{
$con = Connection::createConnection();
$share = ServerConstants::SHARE;
$csp = $gameProgress->csp;
$friendUser = $gameProgress->friend->user;
$count = mysql_query("SELECT count(*) as count FROM gameprogress,progresstype where gameprogress.progresstypeid = progresstype.id AND progresstype.progresstype = '{$share}' AND gameprogress.cspid = {$csp->id} AND gameprogress.friendid = {$friendUser->id}");
while ($row = mysql_fetch_array($count)) {
$rowcount = $row['count'];
}
$base = 0.5;
$rowcount = $rowcount + 1;
$progress = pow($base, $rowcount) * $gameProfile->shareLvl * 5;
$progressType = $this->giveProgressTypeObj(ServerConstants::SHARE);
$insert = mysql_query("insert into gameprogress values (NULL,{$csp->id},{$friendUser->id},{$progressType->id})");
mysql_query("commit");
Connection::closeConnection($con);
return $progress;
}
示例8: updateCurrentSearchPartyProgress
/**
*
* @param <CurrentSearchParty> $currentSearchParty
* @return <CurrentSearchParty>
* @SQL update currentsearchparty,artifactinfo set progress = 10 where currentsearchparty.id = 1 AND (select isactive from artifactinfo where artifactinfo.id= currentsearchparty.artifactid) = 1
*/
public function updateCurrentSearchPartyProgress($currentSearchParty)
{
$con = Connection::createConnection();
$result = mysql_query("update currentsearchparty,artifactinfo set progress = '{$currentSearchParty->progress}' where currentsearchparty.id = '{$currentSearchParty->id}' AND (select isactive from artifactinfo where artifactinfo.id= currentsearchparty.artifactid) = 1");
if (mysql_affected_rows() < 1) {
//means the current search party we want to update the artifact of that party is not active
Connection::closeConnection($con);
return null;
}
Connection::closeConnection($con);
return $currentSearchParty;
}
示例9: set_include_path
<?php
set_include_path(get_include_path() . ';' . realpath(__DIR__));
function _autoloader($className)
{
$filePath = str_replace('_', '/', $className) . ".php";
require_once $filePath;
}
spl_autoload_register("_autoloader");
$config = (include __DIR__ . '/../config/config.php');
Connection::setConnection(Connection::createConnection($config['db']['host'], $config['db']['user'], $config['db']['password'], $config['db']['dbname']));
View::setViewPath($config['viewPath']);