本文整理汇总了PHP中OCP\DB::insertid方法的典型用法代码示例。如果您正苦于以下问题:PHP DB::insertid方法的具体用法?PHP DB::insertid怎么用?PHP DB::insertid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OCP\DB
的用法示例。
在下文中一共展示了DB::insertid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: import
function import()
{
switch ($this->appinfo->version) {
default:
// All versions of the app have had the same db structure, so all can use the same import function
$query = $this->content->prepare('SELECT * FROM contacts_addressbooks WHERE userid = ?');
$results = $query->execute(array($this->olduid));
$idmap = array();
$app = new \OCA\Contacts\App($this->uid);
while ($row = $results->fetchRow()) {
// Import each addressbook
$addressbookquery = \OCP\DB::prepare('INSERT INTO `*PREFIX*contacts_addressbooks` ' . '(`userid`, `displayname`, `uri`, `description`, `ctag`) VALUES (?, ?, ?, ?, ?)');
$addressbookquery->execute(array($this->uid, $row['displayname'], $row['uri'], $row['description'], $row['ctag']));
// Map the id
$idmap[$row['id']] = \OCP\DB::insertid('*PREFIX*contacts_addressbooks');
// Make the addressbook active
$addressbook = $app->getAddressBook('local', $idmap[$row['id']]);
$addressbook->setActive(true);
}
// Now tags
foreach ($idmap as $oldid => $newid) {
$query = $this->content->prepare('SELECT * FROM contacts_cards WHERE addressbookid = ?');
$results = $query->execute(array($oldid));
while ($row = $results->fetchRow()) {
// Import the contacts
$contactquery = \OCP\DB::prepare('INSERT INTO `*PREFIX*contacts_cards` ' . '(`addressbookid`, `fullname`, `carddata`, `uri`, `lastmodified`) VALUES (?, ?, ?, ?, ?)');
$contactquery->execute(array($newid, $row['fullname'], $row['carddata'], $row['uri'], $row['lastmodified']));
}
}
// All done!
break;
}
return true;
}
示例2: add
public static function add($esId, $userId)
{
$query = \OCP\DB::prepare('
INSERT INTO `*PREFIX*documents_invite` (`es_id`, `uid`, `status`, `sent_on`)
VALUES (?, ?, ?, ?)
');
$query->execute(array($esId, $userId, self::STATUS_SENT, time()));
return \OCP\DB::insertid(`*PREFIX*documents_invite`);
}
示例3: collectionNameToIndex
/**
* @brief Get index of collection, if collection doesn't exist it will be created
*
* @param string $collectionName
*/
public static function collectionNameToIndex($userId, $collectionName)
{
$query = \OCP\DB::prepare('SELECT id FROM *PREFIX*mozilla_sync_collections WHERE userid=? AND name=?');
$result = $query->execute(array($userId, $collectionName));
$row = $result->fetchRow();
if ($row) {
return $row['id'];
}
//
// No collection found
//
$query = \OCP\DB::prepare('INSERT INTO *PREFIX*mozilla_sync_collections (userid, name) VALUES (?,?)');
$result = $query->execute(array($userId, $collectionName));
if ($result == false) {
return false;
}
return \OCP\DB::insertid('*PREFIX*mozilla_sync_collections');
}
示例4: collectionNameToIndex
/**
* @brief Get index of collection, if collection doesn't exist it will be
* created.
*
* @param string $syncId The Sync user that the collection is belonging to.
* @param string $collectionName The name of the collection.
*/
public static function collectionNameToIndex($syncId, $collectionName)
{
$query = \OCP\DB::prepare('SELECT `id` FROM
`*PREFIX*mozilla_sync_collections` WHERE `userid` = ? AND
`name` = ?');
$result = $query->execute(array($syncId, $collectionName));
// Collection found, return its ID
$row = $result->fetchRow();
if ($row) {
return $row['id'];
}
// No collection found, create new collection
$query = \OCP\DB::prepare('INSERT INTO
`*PREFIX*mozilla_sync_collections` (`userid`, `name`) VALUES
(?, ?)');
$result = $query->execute(array($syncId, $collectionName));
// Creation of collection failed
if ($result === false) {
Utils::writeLogDbError("DB: Could not create collection " . $collectionName . ".", $query);
return false;
}
return \OCP\DB::insertid('*PREFIX*mozilla_sync_collections');
}
示例5: getInsertId
/**
* Used to get the id of the just inserted element
* @param string $tableName the name of the table where we inserted the item
* @return int the id of the inserted element
*/
public function getInsertId($tableName)
{
return \OCP\DB::insertid($tableName);
}
示例6: addCalendarFromDAVData
/**
* @brief Creates a new calendar from the data sabredav provides
* @param string $principaluri
* @param string $uri
* @param string $name
* @param string $components
* @param string $timezone
* @param integer $order
* @param string $color format: '#RRGGBB(AA)'
* @return insertid
*/
public static function addCalendarFromDAVData($principaluri, $uri, $name, $components, $timezone, $order, $color, $transparent)
{
$userid = self::extractUserID($principaluri);
$all = self::allCalendars($userid);
$uris = array();
foreach ($all as $i) {
$uris[] = $i['uri'];
}
$lastmodified = time();
$uri = self::createURI($name, $uris);
$stmt = \OCP\DB::prepare('INSERT INTO `' . App::CldCalendarTable . '` (`userid`,`displayname`,`uri`,`ctag`,`calendarorder`,`calendarcolor`,`timezone`,`components`,`transparent`) VALUES(?,?,?,?,?,?,?,?,?)');
$result = $stmt->execute(array($userid, $name, $uri, 1, $order, $color, $timezone, $components, $transparent));
$insertid = \OCP\DB::insertid(App::CldCalendarTable);
\OCP\Util::emitHook('\\OCA\\CalendarPlus', 'addCalendar', $insertid);
return $insertid;
}
示例7: addFromDAVData
/**
* @brief Creates a new address book from the data sabredav provides
* @param string $principaluri
* @param string $uri
* @param string $name
* @param string $description
* @return insertid or false
*/
public static function addFromDAVData($principaluri, $uri, $name, $description)
{
$uid = self::extractUserID($principaluri);
try {
$stmt = \OCP\DB::prepare('INSERT INTO `*PREFIX*contacts_addressbooks` ' . '(`userid`,`displayname`,`uri`,`description`,`ctag`) VALUES(?,?,?,?,?)');
$result = $stmt->execute(array($uid, $name, $uri, $description, 1));
if (\OC_DB::isError($result)) {
\OC_Log::write('contacts', __METHOD__ . 'DB error: ' . \OC_DB::getErrorMessage($result), \OC_Log::ERROR);
return false;
}
} catch (Exception $e) {
\OCP\Util::writeLog('contacts', __METHOD__ . ', exception: ' . $e->getMessage(), \OCP\Util::ERROR);
\OCP\Util::writeLog('contacts', __METHOD__ . ', uid: ' . $uid, \OCP\Util::DEBUG);
\OCP\Util::writeLog('contacts', __METHOD__ . ', uri: ' . $uri, \OCP\Util::DEBUG);
return false;
}
return \OCP\DB::insertid('*PREFIX*contacts_addressbooks');
}
示例8: newTag
/**
* Create a new tag with the provided parameters - Return the tag ID
* @param string $tagLang
* @param string $tagDescr
* @param integer $parentID Id of tag's parent
* @param string $owner id of the owner; if NULL the actual username will be set
* @param string $permission unix-style of the read/write permission of the tag
* @return integer Newly inserted index, FALSE if parameters not valid
*/
public function newTag($tagLang, $tagDescr, $parentID, $owner = NULL, $permission = 'rw----')
{
// Check if provided parameters are correct
if (strlen(trim($tagLang)) !== 2 || trim($tagDescr) === '' || !is_int($parentID) || $parentID < -1) {
return FALSE;
}
// Check if tag already exists
if (count($this->searchTag($tagLang, $tagDescr)) != 0) {
return FALSE;
}
// If owner is not set, assign the actual username
if ($owner === NULL) {
$owner = \OCP\User::getUser();
}
// Proceed with creation
$result = array();
// Insert master record
$sql = "INSERT INTO `*PREFIX*oclife_tags` (`parent`, `owner`, `permission`) VALUES (?,?,?)";
$args = array($parentID, $owner, $permission);
$query = \OCP\DB::prepare($sql);
$resRsrc = $query->execute($args);
// Get inserted index
$newIndex = \OCP\DB::insertid();
// Insert human readable
$args = array($newIndex, strtolower($tagLang), trim($tagDescr));
$sql = "INSERT INTO `*PREFIX*oclife_humanReadable` (`tagid`, `lang`, `descr`) VALUES (?,?,?)";
$query = \OCP\DB::prepare($sql);
$resRsrc = $query->execute($args);
return $newIndex;
}
示例9: save
/**
* @brief Store the folder and all its feeds into the database
* @param folder the folder to be saved
* @returns The id of the folder in the database table.
*/
public function save(Folder $folder)
{
$query = \OCP\DB::prepare('
INSERT INTO ' . self::tableName . '(name, parent_id, user_id, opened)
VALUES (?, ?, ?, ?)
');
$name = $folder->getName();
if (empty($name)) {
$l = \OC_L10N::get('news');
$name = $l->t('no name');
}
$parentid = $folder->getParentId();
$params = array($name, $parentid, $this->userid, $folder->getOpened());
$query->execute($params);
$folderid = \OCP\DB::insertid(self::tableName);
$folder->setId($folderid);
return $folderid;
}
示例10: createContact
/**
* Creates a new contact
*
* In the Database and Shared backends contact be either a Contact object or a string
* with carddata to be able to play seamlessly with the CardDAV backend.
* If this method is called by the CardDAV backend, the carddata is already validated.
* NOTE: It's assumed that this method is called either from the CardDAV backend, the
* import script, or from the ownCloud web UI in which case either the uri parameter is
* set, or the contact has a UID. If neither is set, it will fail.
*
* @param string $addressbookid
* @param VCard|string $contact
* @param array $options - Optional (backend specific options)
* @return string|bool The identifier for the new contact or false on error.
*/
public function createContact($addressbookid, $contact, array $options = array())
{
$qname = 'createcontact';
$uri = isset($options['uri']) ? $options['uri'] : null;
if (!$contact instanceof VCard) {
try {
$contact = Reader::read($contact);
} catch (\Exception $e) {
\OCP\Util::writeLog('contacts', __METHOD__ . ', exception: ' . $e->getMessage(), \OCP\Util::ERROR);
return false;
}
}
try {
$contact->validate(VCard::REPAIR | VCard::UPGRADE);
} catch (\Exception $e) {
OCP\Util::writeLog('contacts', __METHOD__ . ' ' . 'Error validating vcard: ' . $e->getMessage(), \OCP\Util::ERROR);
return false;
}
$uri = is_null($uri) ? $contact->UID . '.vcf' : $uri;
$now = new \DateTime();
$contact->REV = $now->format(\DateTime::W3C);
$appinfo = \OCP\App::getAppInfo('contacts');
$appversion = \OCP\App::getAppVersion('contacts');
$prodid = '-//ownCloud//NONSGML ' . $appinfo['name'] . ' ' . $appversion . '//EN';
$contact->PRODID = $prodid;
$data = $contact->serialize();
if (!isset(self::$preparedQueries[$qname])) {
self::$preparedQueries[$qname] = \OCP\DB::prepare('INSERT INTO `' . $this->cardsTableName . '` (`addressbookid`,`fullname`,`carddata`,`uri`,`lastmodified`) VALUES(?,?,?,?,?)');
}
try {
$result = self::$preparedQueries[$qname]->execute(array($addressbookid, (string) $contact->FN, $contact->serialize(), $uri, time()));
if (\OCP\DB::isError($result)) {
\OCP\Util::writeLog('contacts', __METHOD__ . 'DB error: ' . \OC_DB::getErrorMessage($result), \OCP\Util::ERROR);
return false;
}
} catch (\Exception $e) {
\OCP\Util::writeLog('contacts', __METHOD__ . ', exception: ' . $e->getMessage(), \OCP\Util::ERROR);
return false;
}
$newid = \OCP\DB::insertid($this->cardsTableName);
$this->touchAddressBook($addressbookid);
\OCP\Util::emitHook('OCA\\Contacts', 'post_createContact', array('id' => $newid, 'parent' => $addressbookid, 'contact' => $contact));
return (string) $newid;
}
示例11: addSong
/**
* Add an song to the database
*
* @param string $name
* @param string $path
* @param int $artist
* @param int $album
* @param int $length
* @param int $track
* @param int $size
* @return int the song_id of the added artist
*/
public function addSong($name, $path, $artist, $album, $length, $track, $size)
{
$name = trim($name);
$path = trim($path);
if ($name == '' or $path == '') {
return 0;
}
//check if the song is already in the database
$songId = $this->getSongId($name, $artist, $album);
if ($songId != 0) {
$songInfo = $this->getSong($songId);
$this->moveSong($songInfo['song_path'], $path);
return $songId;
}
if ($this->getSongCountByPath($path) !== 0) {
$this->deleteSongByPath($path);
}
$query = \OCP\DB::prepare("INSERT INTO `*PREFIX*media_songs` (`song_name` ,`song_artist` ,`song_album` ,`song_path` ,`song_user`,`song_length`,`song_track`,`song_size`,`song_playcount`,`song_lastplayed`)\n\t\t\tVALUES (?, ?, ?, ?, ?, ?, ?, ?, 0, 0)");
$query->execute(array($name, $artist, $album, $path, $this->uid, $length, $track, $size));
\OCP\DB::insertid(' * PREFIX * media_songs_song');
return $this->getSongId($name, $artist, $album);
}
示例12: array
} else {
$field = 'match';
}
$data = array();
$data[] = $statusType;
$data[] = isset($_POST['match']) ? $_POST['match'] : '';
$data[] = isset($_POST['description']) ? $_POST['description'] : '';
$data[] = isset($_POST['status']) ? intval($_POST['status']) : 0;
if ($ruleId) {
$data[] = $ruleId;
$query = \OCP\DB::prepare('UPDATE `*PREFIX*files_antivirus_status` SET `status_type`=(?),' . ' `' . $field . '`=(?), `description`=(?), `status`=(?) WHERE `id`=?');
} else {
$query = \OCP\DB::prepare('INSERT INTO `*PREFIX*files_antivirus_status` (`status_type`,' . ' `' . $field . '`, `description`, `status`) VALUES (?, ?, ?, ?)');
}
$query->execute($data);
$result = array();
if (!$ruleId) {
$result['id'] = \OCP\DB::insertid('`*PREFIX*files_antivirus_status`');
}
\OCP\JSON::success($result);
break;
case 'delete':
$ruleId = isset($_POST['id']) ? intval($_POST['id']) : 0;
$query = \OCP\DB::prepare('DELETE FROM `*PREFIX*files_antivirus_status` WHERE `id`=?');
$query->execute(array($ruleId));
\OCP\JSON::success();
break;
default:
break;
}
exit;
示例13: createNote
public function createNote($FOLDER, $in_name, $in_group)
{
$name = str_replace("\\", "-", str_replace("/", "-", $in_name));
$group = str_replace("\\", "-", str_replace("/", "-", $in_group));
$now = new DateTime();
$mtime = $now->getTimestamp();
$uid = \OCP\User::getUser();
$fileindb = false;
$filedeldb = false;
$ret = -1;
$query = \OCP\DB::prepare("SELECT id, name, grouping, mtime, deleted FROM *PREFIX*ownnote WHERE uid=? and name=? and grouping=?");
$results = $query->execute(array($uid, $name, $group))->fetchAll();
foreach ($results as $result) {
if ($result['deleted'] == 0) {
$fileindb = true;
$ret = $result['id'];
} else {
$filedeldb = true;
}
}
if ($filedeldb) {
$query = \OCP\DB::prepare("DELETE FROM *PREFIX*ownnote WHERE uid=? and name=? and grouping=?");
$results = $query->execute(array($uid, $name, $group));
}
if (!$fileindb) {
if ($FOLDER != '') {
$tmpfile = $FOLDER . "/" . $name . ".htm";
if ($group != '') {
$tmpfile = $FOLDER . "/[" . $group . "] " . $name . ".htm";
}
if (!\OC\Files\Filesystem::file_exists($tmpfile)) {
\OC\Files\Filesystem::touch($tmpfile);
}
if ($info = \OC\Files\Filesystem::getFileInfo($tmpfile)) {
$mtime = $info['mtime'];
}
}
$query = \OCP\DB::prepare("INSERT INTO *PREFIX*ownnote (uid, name, grouping, mtime, note, shared) VALUES (?,?,?,?,?,?)");
$query->execute(array($uid, $name, $group, $mtime, '', ''));
$ret = \OCP\DB::insertid('*PREFIX*ownnote');
}
return $ret;
}
示例14: add
/**
* Add a new tag.
*
* @param string $name A string with a name of the tag
* @return false|string the id of the added tag or false on error.
*/
public function add($name)
{
$name = trim($name);
if ($name === '') {
\OCP\Util::writeLog('core', __METHOD__ . ', Cannot add an empty tag', \OCP\Util::DEBUG);
return false;
}
if ($this->hasTag($name)) {
\OCP\Util::writeLog('core', __METHOD__ . ', name: ' . $name . ' exists already', \OCP\Util::DEBUG);
return false;
}
try {
$result = \OCP\DB::insertIfNotExist(self::TAG_TABLE, array('uid' => $this->user, 'type' => $this->type, 'category' => $name));
if (\OCP\DB::isError($result)) {
\OCP\Util::writeLog('core', __METHOD__ . 'DB error: ' . \OCP\DB::getErrorMessage($result), \OCP\Util::ERROR);
return false;
} elseif ((int) $result === 0) {
\OCP\Util::writeLog('core', __METHOD__ . ', Tag already exists: ' . $name, \OCP\Util::DEBUG);
return false;
}
} catch (\Exception $e) {
\OCP\Util::writeLog('core', __METHOD__ . ', exception: ' . $e->getMessage(), \OCP\Util::ERROR);
return false;
}
$id = \OCP\DB::insertid(self::TAG_TABLE);
\OCP\Util::writeLog('core', __METHOD__ . ', id: ' . $id, \OCP\Util::DEBUG);
$this->tags[$id] = $name;
return $id;
}
示例15: addFromDAVData
/**
* @brief Adds an object with the data provided by sabredav
* @param integer $id Calendar id
* @param string $uri the uri the card will have
* @param string $data object
* @return insertid
*/
public static function addFromDAVData($id, $uri, $data)
{
$calendar = Calendar::find($id);
if ($calendar['userid'] != \OCP\User::getUser()) {
$sharedCalendar = \OCP\Share::getItemSharedWithBySource(App::SHARECALENDAR, App::SHARECALENDARPREFIX . $id);
if (!$sharedCalendar || !($sharedCalendar['permissions'] & \OCP\PERMISSION_CREATE)) {
throw new \Sabre\DAV\Exception\Forbidden(App::$l10n->t('You do not have the permissions to add events to this calendar.'));
}
}
$object = VObject::parse($data);
list($type, $startdate, $enddate, $summary, $repeating, $uid, $isAlarm, $relatedTo) = self::extractData($object);
$stmt = \OCP\DB::prepare('INSERT INTO `' . App::CldObjectTable . '` (`calendarid`,`objecttype`,`startdate`,`enddate`,`repeating`,`summary`,`calendardata`,`uri`,`lastmodified`,`isalarm`,`eventuid`,`relatedto`) VALUES(?,?,?,?,?,?,?,?,?,?,?,?)');
$stmt->execute(array($id, $type, $startdate, $enddate, $repeating, $summary, $data, $uri, time(), $isAlarm, $uid, $relatedTo));
$object_id = \OCP\DB::insertid(App::CldObjectTable);
Calendar::touchCalendar($id);
$app = new Application();
$c = $app->getContainer();
$repeatController = $c->query('RepeatController');
$repeatController->generateEventCache($object_id);
//\OCP\Util::emitHook('\OCA\CalendarPlus', 'addEvent', $object_id);
$linkTypeApp = App::$appname;
if ($type == 'VTODO') {
$linkTypeApp = 'tasksplus';
}
$link = \OC::$server->getURLGenerator()->linkToRoute($linkTypeApp . '.page.index') . '#' . urlencode($object_id);
$params = array('mode' => 'created', 'link' => $link, 'trans_type' => App::$l10n->t($type), 'summary' => $summary, 'cal_user' => $calendar['userid'], 'cal_displayname' => $calendar['displayname']);
ActivityData::logEventActivity($params, true);
return $object_id;
}