本文整理汇总了PHP中QueryBuilder::insert方法的典型用法代码示例。如果您正苦于以下问题:PHP QueryBuilder::insert方法的具体用法?PHP QueryBuilder::insert怎么用?PHP QueryBuilder::insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QueryBuilder
的用法示例。
在下文中一共展示了QueryBuilder::insert方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generate
/**
*
* Generate code using given parameters
* @param array $paramsArray
*/
public function generate(OTCConfig $config = null)
{
if ($config === null) {
$config = new OTCConfig();
}
$paramsArray = $config->paramsArray;
if (isset($paramsArray['r'])) {
throw new RuntimeException("Key 'r' is not allowed to be present in \$paramsArray. Please remove or rename it.");
}
$paramsArray['r'] = generateRandomString(12);
$keyValArray = array();
$keysUniqueCheckArray = array();
foreach ($paramsArray as $key => $value) {
if (preg_match("/[:;]/", $key) or preg_match("/[:;]/", $value)) {
throw new RuntimeException("Invalid characters in \$paramsArray. No ; or : characters are allowed!");
}
if (in_array($key, $keysUniqueCheckArray)) {
throw new RuntimeException("Duplicate key '{$key}' in \$paramsArray. It's not allowed!");
}
array_push($keysUniqueCheckArray, $key);
array_push($keyValArray, "{$key}:{$value}");
}
$stringToEncrypt = implode(";", $keyValArray);
$encryptedString = AES256::encrypt($stringToEncrypt);
if (strlen($encryptedString) > static::CODE_MAX_LENGTH) {
throw new RuntimeException("Resulting code is longer than allowed " . static::CODE_MAX_LENGTH . " characters!");
}
$qb = new QueryBuilder();
$qb->insert(Tbl::get('TBL_ONE_TIME_CODES'))->values(array("code" => $encryptedString, "multi" => $config->multiUse ? 1 : 0, "usage_limit" => $config->usageLimit ? $config->usageLimit : new Literal("NULL"), "not_cleanable" => $config->notCleanable ? 1 : 0, "valid_until" => $config->validityTime ? new Func('FROM_UNIXTIME', $qb->expr()->sum(new Func('UNIX_TIMESTAMP', new Func('NOW')), $config->validityTime)) : new Literal("NULL")));
$this->query->exec($qb->getSQL());
return $encryptedString;
}
示例2: blockIP
/**
* Block given IP
* @param string $ip
*/
public function blockIP($ip = null)
{
if ($ip === null) {
$ip = $_SERVER['REMOTE_ADDR'];
}
$qb = new QueryBuilder();
$qb->insert(Tbl::get('TBL_SECURITY_FLOODER_IPS'))->values(array('ip' => $ip));
$this->query->exec($qb->getSQL());
}
示例3: addPermissionToGroup
public function addPermissionToGroup(Permission $perm, UserGroup $group, $args = null)
{
$qb = new QueryBuilder();
$values = array('group_id' => $group->id, 'permission_id' => $perm->id);
if ($args !== null) {
$values['args'] = serialize($args);
}
$qb->insert(Tbl::get('TBL_GROUPS_PERMISSIONS', 'UserManager'))->values($values);
return $this->query->exec($qb->getSQL())->affected();
}
示例4: addGroup
public function addGroup(TextsGroup $group)
{
if (empty($group->name)) {
throw new InvalidArgumentException("You have to specify name for new group");
}
$qb = new QueryBuilder();
$qb->insert(Tbl::get('TBL_TEXTS_GROUPS'))->values(array("name" => $group->name));
$this->query->exec($qb->getSQL());
return $this->query->affected();
}
示例5: logCustom
public static function logCustom($name, $value)
{
$remoteIP = "";
if (isset($_SERVER['REMOTE_ADDR'])) {
$remoteIP = $_SERVER['REMOTE_ADDR'];
}
$qb = new QueryBuilder();
$qb->insert(Tbl::get('TBL_MIXED_LOG'))->values(array("session_id" => session_id(), "name" => $name, "value" => $value, "ip" => $remoteIP));
Reg::get('sql')->exec($qb->getSQL());
}
示例6: fillUsersGps
public function fillUsersGps($userId, $leafId)
{
$qb = new QueryBuilder();
$qb->delete(Tbl::get('TBL_USERS_GPS'))->where($qb->expr()->equal(new Field('user_id'), $userId));
$this->query->exec($qb->getSQL());
$gpsTree = $this->getNodeTree($leafId);
foreach ($gpsTree as $treeNode) {
$qb = new QueryBuilder();
$qb->insert(Tbl::get('TBL_USERS_GPS'))->values(array('user_id' => $userId, 'node_id' => $treeNode["node_id"]));
$this->query->exec($qb->getSQL());
}
}
示例7: setControllerTemplateByHost
public static function setControllerTemplateByHost(Host $host, $controller, $template)
{
$sql = MySqlDbManager::getQueryObject();
$qb = new QueryBuilder();
if (!empty($controller) or !empty($template)) {
$qb->insert(Tbl::get('TBL_HOST_CONTROLLER_TEMPLATE'))->values(array('host_id' => $host->id, 'controller' => $controller, 'template' => $template))->onDuplicateKeyUpdate()->set(new Field('controller'), $controller)->set(new Field('template'), $template);
} else {
$qb->delete(Tbl::get('TBL_HOST_CONTROLLER_TEMPLATE'))->where($qb->expr()->equal(new Field('host_id'), $host->id));
}
$sql->exec($qb->getSQL());
return $sql->affected();
}
示例8: insertMessage
/**
* Insert ChatMessage object to database
*
* @param ChatMessage $chatMessage
* @return int inserted message Id
*/
public function insertMessage(ChatMessage $chatMessage)
{
if (empty($chatMessage->senderUser->userId) or !is_numeric($chatMessage->senderUser->userId)) {
throw new InvalidArgumentException("Invalid senderUser specified!");
}
if (empty($chatMessage->receiverUser->userId) or !is_numeric($chatMessage->receiverUser->userId)) {
throw new InvalidArgumentException("Invalid receiverUser specified!");
}
$qb = new QueryBuilder();
$qb->insert(Tbl::get('TBL_CHAT_MESSAGES'))->values(array("sender_user_id" => $chatMessage->senderUser->userId, "receiver_user_id" => $chatMessage->receiverUser->userId, "message" => $chatMessage->message, "is_system" => $chatMessage->is_system));
$this->query->exec($qb->getSQL());
return $this->query->getLastInsertId();
}
示例9: insertInvitation
public function insertInvitation(ChatInvitation $invitation)
{
if (empty($invitation->inviterUser->userId) or !is_numeric($invitation->inviterUser->userId)) {
throw new InvalidArgumentException("Invalid inviterUser specified!");
}
if (empty($invitation->invitedUser->userId) or !is_numeric($invitation->invitedUser->userId)) {
throw new InvalidArgumentException("Invalid invitedUser specified!");
}
$qb = new QueryBuilder();
$qb->insert(Tbl::get('TBL_CHAT_INVITATIONS'))->values(array("sender_user_id" => $invitation->inviterUser->userId, "receiver_user_id" => $invitation->invitedUser->userId, "invitation_message" => $invitation->invitationMessage, "status" => $invitation->status));
$this->query->exec($qb->getSQL());
return $this->query->getLastInsertId();
}
示例10: logRequest
public static function logRequest($dbInstanceKey = null)
{
$sql = MySqlDbManager::getQueryObject($dbInstanceKey);
$userId = "NULL";
$userObjectSerialized = "''";
$userObj = Reg::get(ConfigManager::getConfig("Users", "Users")->ObjectsIgnored->User);
if ($userObj->isAuthorized()) {
$userId = $userObj->id;
$userObjectSerialized = "'" . mysql_real_escape_string(serialize($userObj)) . "'";
}
$qb = new QueryBuilder();
$qb->insert(Tbl::get('TBL_REQUEST_LOG'))->values(array("user_id" => $userId, "user_obj" => $userObjectSerialized, "session_id" => session_id(), "get" => serialize($_GET), "post" => serialize($_POST), "server" => serialize($_SERVER), "cookies" => serialize($_COOKIE), "session" => serialize($_SESSION), "response" => ob_get_contents()));
$sql->exec($qb->getSQL());
}
示例11: addHost
public static function addHost(Host $host)
{
if (empty($host->host)) {
throw new InvalidArgumentException("Host name is empty!");
}
$values = array("host" => $host->host);
if (!empty($host->subdomain)) {
$values["subdomain"] = $host->subdomain;
}
$qb = new QueryBuilder();
$qb->insert(Tbl::get('TBL_HOSTS', 'Host'))->values($values);
$sql = MySqlDbManager::getQueryObject();
$sql->exec($qb->getSQL());
$host->id = $sql->getLastInsertId();
}
示例12: addText
public function addText(Text $text, TextsGroup $group)
{
if (empty($text->name)) {
throw new InvalidArgumentException("You have to specify name for new text");
}
if (empty($group->id)) {
throw new InvalidArgumentException("Group ID have to be specified");
}
if (!is_numeric($group->id)) {
throw new InvalidArgumentException("Group ID have to be integer");
}
$qb = new QueryBuilder();
$qb->insert(Tbl::get('TBL_TEXTS'))->values(array('group_id' => $group->id, 'name' => $text->name, 'description' => $text->description));
$this->query->exec($qb->getSQL());
return $this->query->affected();
}
示例13: addAttachment
/**
*
* @param array $file e.g. $_FILES['photo']
* @return ConversationAttachment
*/
public function addAttachment($file)
{
$systemFilename = self::findNewFileName($this->config->uploadDir);
$attachsImgUpConfig = $this->config->imageUploaderConfig;
$attachsImgUpConfig->uploadDir = $this->config->uploadDir;
if (in_array($file["type"], $attachsImgUpConfig->acceptedMimeTypes->toArray())) {
ImageUploader::upload($file, $systemFilename, $attachsImgUpConfig);
} else {
FileUploader::upload($file, $systemFilename, $this->config->uploadDir);
}
$qb = new QueryBuilder();
$qb->insert(Tbl::get('TBL_CONVERSATION_ATTACHEMENTS'))->values(array('system_filename' => $systemFilename, 'filename' => $file['name'], 'mime_type' => $file['type']));
$attachmentId = $this->query->exec($qb->getSQL())->getLastInsertId();
$filter = new ConversationAttachmentFilter();
$filter->setId($attachmentId);
return $this->getAttachment($filter);
}
示例14: addPhoto
public function addPhoto(UserPhoto $photo)
{
if (empty($photo)) {
throw new InvalidArgumentException("\$photo is empty!");
}
if (empty($photo->fileName)) {
throw new InvalidArgumentException("photo fileName is have to been non empty string!");
}
$qb = new QueryBuilder();
$qb->insert(Tbl::get('TBL_USERS_PHOTOS'))->values(array("user_id" => $photo->userId, "filename" => $photo->fileName, "status" => $photo->status));
$this->query->exec($qb->getSQL());
$photoId = $this->query->getLastInsertId();
if ($photo->status == self::MODERATION_STATUS_APPROVED) {
$this->correctDefaultPhoto($photo->userId);
}
return $photoId;
}
示例15: hookInvalidLoginAttempt
public function hookInvalidLoginAttempt($params)
{
if ($this->config->AuxConfig->loginBruteForceProtectionEnabled) {
if (isset($_SERVER['REMOTE_ADDR'])) {
$sql = MySqlDbManager::getQueryObject();
$qb = new QueryBuilder();
$sql->exec($qb->select(new Field('count'))->from(Tbl::get('TBL_SECURITY_INVALID_LOGINS_LOG', 'RequestLimiter'))->where($qb->expr()->equal(new Field('ip'), $_SERVER['REMOTE_ADDR']))->getSQL());
$failedAuthCount = $sql->fetchField('count');
$newFailedAuthCount = $failedAuthCount + 1;
if ($newFailedAuthCount >= $this->config->AuxConfig->failedLoginLimit) {
Reg::get(ConfigManager::getConfig("Security", "RequestLimiter")->Objects->RequestLimiter)->blockIP();
$qb = new QueryBuilder();
$sql->exec($qb->delete(Tbl::get('TBL_SECURITY_INVALID_LOGINS_LOG', 'RequestLimiter'))->where($qb->expr()->equal(new Field('ip'), $_SERVER['REMOTE_ADDR']))->getSQL());
throw new RequestLimiterTooManyAuthTriesException("Too many unsucessful authorization tries.");
}
$qb = new QueryBuilder();
$sql->exec($qb->insert(Tbl::get('TBL_SECURITY_INVALID_LOGINS_LOG', 'RequestLimiter'))->values(array('ip' => $_SERVER['REMOTE_ADDR']))->onDuplicateKeyUpdate()->set(new Field('count'), $qb->expr()->sum(new Field('count'), 1))->getSQL());
}
}
}