本文整理汇总了PHP中OC\DB\Connection::insert方法的典型用法代码示例。如果您正苦于以下问题:PHP Connection::insert方法的具体用法?PHP Connection::insert怎么用?PHP Connection::insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OC\DB\Connection
的用法示例。
在下文中一共展示了Connection::insert方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setValue
/**
* sets a value in the appconfig
*
* @param string $app app
* @param string $key key
* @param string $value value
*
* Sets a value. If the key did not exist before it will be created.
*/
public function setValue($app, $key, $value)
{
// Does the key exist? no: insert, yes: update.
if (!$this->hasKey($app, $key)) {
$data = array('appid' => $app, 'configkey' => $key, 'configvalue' => $value);
$this->conn->insert('*PREFIX*appconfig', $data);
} else {
$oldValue = $this->getValue($app, $key);
if ($oldValue === strval($value)) {
return true;
}
$data = array('configvalue' => $value);
$where = array('appid' => $app, 'configkey' => $key);
$this->conn->update('*PREFIX*appconfig', $data, $where);
}
if (!isset($this->cache[$app])) {
$this->cache[$app] = array();
}
if (is_array($this->apps) and array_search($app, $this->apps) === false) {
$this->apps[$app] = $app;
}
$this->cache[$app][$key] = $value;
}
示例2: setValue
/**
* sets a value in the preferences
* @param string $user user
* @param string $app app
* @param string $key key
* @param string $value value
* @param string $preCondition only set value if the key had a specific value before
* @return bool true if value was set, otherwise false
*
* Adds a value to the preferences. If the key did not exist before, it
* will be added automagically.
*/
public function setValue($user, $app, $key, $value, $preCondition = null)
{
// Check if the key does exist
$query = 'SELECT `configvalue` FROM `*PREFIX*preferences`' . ' WHERE `userid` = ? AND `appid` = ? AND `configkey` = ?';
$oldValue = $this->conn->fetchColumn($query, array($user, $app, $key));
$exists = $oldValue !== false;
if ($oldValue === strval($value)) {
// no changes
return true;
}
$affectedRows = 0;
if (!$exists && $preCondition === null) {
$data = array('userid' => $user, 'appid' => $app, 'configkey' => $key, 'configvalue' => $value);
$affectedRows = $this->conn->insert('*PREFIX*preferences', $data);
} elseif ($exists) {
$data = array($value, $user, $app, $key);
$sql = "UPDATE `*PREFIX*preferences` SET `configvalue` = ?" . " WHERE `userid` = ? AND `appid` = ? AND `configkey` = ?";
if ($preCondition !== null) {
if (\OC_Config::getValue('dbtype', 'sqlite') === 'oci') {
//oracle hack: need to explicitly cast CLOB to CHAR for comparison
$sql .= " AND to_char(`configvalue`) = ?";
} else {
$sql .= " AND `configvalue` = ?";
}
$data[] = $preCondition;
}
$affectedRows = $this->conn->executeUpdate($sql, $data);
}
// only add to the cache if we already loaded data for the user
if ($affectedRows > 0 && isset($this->cache[$user])) {
if (!isset($this->cache[$user][$app])) {
$this->cache[$user][$app] = array();
}
$this->cache[$user][$app][$key] = $value;
}
return $affectedRows > 0 ? true : false;
}
示例3: copyTable
protected function copyTable(Connection $fromDB, Connection $toDB, $table, InputInterface $input, OutputInterface $output)
{
/** @var $progress \Symfony\Component\Console\Helper\ProgressHelper */
$progress = $this->getHelperSet()->get('progress');
$query = 'SELECT COUNT(*) FROM ' . $table;
$count = $fromDB->fetchColumn($query);
$query = 'SELECT * FROM ' . $table;
$statement = $fromDB->executeQuery($query);
$progress->start($output, $count);
$progress->setRedrawFrequency($count > 100 ? 5 : 1);
while ($row = $statement->fetch()) {
$progress->advance();
if ($input->getArgument('type') === 'oci') {
$data = $row;
} else {
$data = array();
foreach ($row as $columnName => $value) {
$data[$toDB->quoteIdentifier($columnName)] = $value;
}
}
$toDB->insert($table, $data);
}
$progress->finish();
}