本文整理匯總了PHP中Doctrine\DBAL\Connection::insert方法的典型用法代碼示例。如果您正苦於以下問題:PHP Connection::insert方法的具體用法?PHP Connection::insert怎麽用?PHP Connection::insert使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Doctrine\DBAL\Connection
的用法示例。
在下文中一共展示了Connection::insert方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: insertTableRows
/**
* @param string $tableName
* @param array $rows
*/
protected function insertTableRows($tableName, array $rows)
{
foreach ($rows as $rowKey => $values) {
$this->connection->insert($tableName, $this->parser->parse($values));
$this->parser->addReference($rowKey, $this->connection->lastInsertId());
}
}
示例2: save
public function save(Order $order)
{
$data = $order->jsonSerialize();
unset($data['id']);
$this->connection->insert($this->getTableName(), $data);
$order->setId($this->connection->lastInsertId());
}
示例3: save
/**
* Saves the pool to the database.
*
* @param \MusicBox\Entity\Like $pool
*/
public function save($pool)
{
$poolData = array('address_id' => $pool->getAddress()->getId(), 'access_info' => $pool->getAccessInfo());
if ($pool->getId()) {
$this->db->update('pools', $poolData, array('pool_id' => $pool->getId()));
$newFile = $this->handleFileUpload($item);
if ($newFile) {
$poolData['image'] = $pool->getImage();
}
} else {
// The pool is new, note the creation timestamp.
$poolData['created_at'] = time();
$this->db->insert('pools', $poolData);
// Get the id of the newly created pool and set it on the entity.
$id = $this->db->lastInsertId();
$pool->setId($id);
// If a new image was uploaded, update the pool with the new
// filename.
$newFile = $this->handleFileUpload($pool);
if ($newFile) {
$newData = array('image' => $pool->getImage());
$this->db->update('pools', $newData, array('pool_id' => $id));
}
}
}
示例4: save
/**
* Saves the artist to the database.
*
* @param \MusicBox\Entity\Artist $artist
*/
public function save($artist)
{
$artistData = array('name' => $artist->getName(), 'short_biography' => $artist->getShortBiography(), 'biography' => $artist->getBiography(), 'soundcloud_url' => $artist->getSoundCloudUrl(), 'image' => $artist->getImage());
if ($artist->getId()) {
// If a new image was uploaded, make sure the filename gets set.
$newFile = $this->handleFileUpload($artist);
if ($newFile) {
$artistData['image'] = $artist->getImage();
}
$this->db->update('artists', $artistData, array('artist_id' => $artist->getId()));
} else {
// The artist is new, note the creation timestamp.
$artistData['created_at'] = time();
$this->db->insert('artists', $artistData);
// Get the id of the newly created artist and set it on the entity.
$id = $this->db->lastInsertId();
$artist->setId($id);
// If a new image was uploaded, update the artist with the new
// filename.
$newFile = $this->handleFileUpload($artist);
if ($newFile) {
$newData = array('image' => $artist->getImage());
$this->db->update('artists', $newData, array('artist_id' => $id));
}
}
}
示例5: save
/**
* Saves the user to the database.
*
* @param \MusicBox\Entity\User $user
*/
public function save($user)
{
$userData = array('username' => $user->getUsername(), 'mail' => $user->getMail(), 'role' => $user->getRole());
// If the password was changed, re-encrypt it.
if (strlen($user->getPassword()) != 88) {
$userData['salt'] = uniqid(mt_rand());
$userData['password'] = $this->encoder->encodePassword($user->getPassword(), $userData['salt']);
}
if ($user->getId()) {
// If a new image was uploaded, make sure the filename gets set.
$newFile = $this->handleFileUpload($user);
if ($newFile) {
$userData['image'] = $user->getImage();
}
$this->db->update('users', $userData, array('user_id' => $user->getId()));
} else {
// The user is new, note the creation timestamp.
$userData['created_at'] = time();
$this->db->insert('users', $userData);
// Get the id of the newly created user and set it on the entity.
$id = $this->db->lastInsertId();
$user->setId($id);
// If a new image was uploaded, update the user with the new
// filename.
$newFile = $this->handleFileUpload($user);
if ($newFile) {
$newData = array('image' => $user->getImage());
$this->db->update('users', $newData, array('user_id' => $id));
}
}
}
示例6: onReminderWasAddedToTodo
/**
* @param ReminderWasAddedToTodo $event
* @return void
*/
public function onReminderWasAddedToTodo(ReminderWasAddedToTodo $event)
{
// remove other reminder for todo first
$this->connection->delete(Table::TODO_REMINDER, ['todo_id' => $event->todoId()->toString()]);
$reminder = $event->reminder();
$this->connection->insert(Table::TODO_REMINDER, ['todo_id' => $event->todoId()->toString(), 'reminder' => $reminder->toString(), 'status' => $reminder->status()->toString()]);
}
示例7: executeUpgrade
public function executeUpgrade(Connection $connection)
{
// update action class names
$actions = ['Fusio\\Action\\BeanstalkPush' => 'Fusio\\Impl\\Action\\MqBeanstalk', 'Fusio\\Action\\CacheResponse' => 'Fusio\\Impl\\Action\\CacheResponse', 'Fusio\\Action\\Composite' => 'Fusio\\Impl\\Action\\Composite', 'Fusio\\Action\\Condition' => 'Fusio\\Impl\\Action\\Condition', 'Fusio\\Action\\HttpRequest' => 'Fusio\\Impl\\Action\\HttpRequest', 'Fusio\\Action\\Pipe' => 'Fusio\\Action\\Pipe', 'Fusio\\Action\\RabbitMqPush' => 'Fusio\\Impl\\Action\\MqAmqp', 'Fusio\\Action\\SqlExecute' => 'Fusio\\Impl\\Action\\SqlExecute', 'Fusio\\Action\\SqlFetchAll' => 'Fusio\\Impl\\Action\\SqlFetchAll', 'Fusio\\Action\\SqlFetchRow' => 'Fusio\\Impl\\Action\\SqlFetchRow', 'Fusio\\Action\\StaticResponse' => 'Fusio\\Impl\\Action\\StaticResponse'];
foreach ($actions as $oldClass => $newClass) {
$connection->executeUpdate('UPDATE fusio_action SET class = :new_class WHERE class = :old_class', ['new_class' => $newClass, 'old_class' => $oldClass]);
}
// update connection class names
$actions = ['Fusio\\Connection\\Beanstalk' => 'Fusio\\Impl\\Connection\\Beanstalk', 'Fusio\\Connection\\DBAL' => 'Fusio\\Impl\\Connection\\DBAL', 'Fusio\\Connection\\DBALAdvanced' => 'Fusio\\Impl\\Connection\\DBALAdvanced', 'Fusio\\Connection\\MongoDB' => 'Fusio\\Impl\\Connection\\MongoDB', 'Fusio\\Connection\\Native' => 'Fusio\\Impl\\Connection\\Native', 'Fusio\\Connection\\RabbitMQ' => 'Fusio\\Impl\\Connection\\RabbitMQ'];
foreach ($actions as $oldClass => $newClass) {
$connection->executeUpdate('UPDATE fusio_connection SET class = :new_class WHERE class = :old_class', ['new_class' => $newClass, 'old_class' => $oldClass]);
}
// update routes class names
$routes = $connection->fetchAll('SELECT id, controller FROM fusio_routes');
foreach ($routes as $route) {
if (substr($route['controller'], 0, 6) == 'Fusio\\' && substr($route['controller'], 0, 11) != 'Fusio\\Impl\\') {
$newController = 'Fusio\\Impl\\' . substr($route['controller'], 6);
$connection->executeUpdate('UPDATE fusio_routes SET controller = :controller WHERE id = :id', ['controller' => $newController, 'id' => $route['id']]);
}
}
// insert new classes table
$data = $this->getInstallInserts();
if (isset($data['fusio_connection_class'])) {
foreach ($data['fusio_connection_class'] as $row) {
$connection->insert('fusio_connection_class', $row);
}
}
if (isset($data['fusio_action_class'])) {
foreach ($data['fusio_action_class'] as $row) {
$connection->insert('fusio_action_class', $row);
}
}
}
示例8: collect
/**
* @return JsonResponse
*/
public function collect()
{
$toSave = array();
$count = 0;
$currentPageIndex = 0;
while ($count < self::NB_POSTS) {
$url = self::getUrl($currentPageIndex++);
try {
$html = $this->curlUtils->getResource($url);
$posts = $this->postParserUtils->getPosts($html);
foreach ($posts as $post) {
if ($count === self::NB_POSTS) {
break;
}
$postContent = $this->postParserUtils->parse($post);
$toSave[$count++] = $postContent;
}
} catch (\Exception $exception) {
return new JsonResponse($exception);
}
}
for ($i = 0; $i < count($toSave); $i++) {
$this->dbal->insert(self::MODEL, $toSave[$i]);
}
$toReturn = count($toSave) . " posts have been added";
return new JsonResponse($toReturn);
}
示例9: save
public function save($user)
{
$userData = array('name' => $user->getName(), 'email' => $user->getEmail(), 'password' => $user->getPassword(), 'joinTime' => $user->getJoinTime(), 'registerIp' => $user->getRegisterIp(), 'sharedKey' => $user->getSharedKey(), 'integration' => $user->getIntegration(), 'shareKey' => $user->getShareKey());
$this->db->insert('user', $userData);
$id = $this->db->lastInsertId();
$user->setId($id);
}
示例10: create
public function create(CacheRecord $cacheRecord)
{
$this->db->insert($this->entityTable, $cacheRecord->toArray());
if ($this->db->lastInsertId() <= 0) {
throw new InvalidArgumentException("The insert failed.");
}
return $this->db->lastInsertId();
}
示例11: write
/**
* {@inheritdoc}
*/
protected function write(array $record)
{
$record = $record['formatted'];
try {
$this->connection->insert($this->tableName, $record);
} catch (\Exception $e) {
}
}
示例12: set
/**
* Sets an item in the store.
*
* @param string $key
* @param mixed $value
*
* @return void
*/
public function set($key, $value)
{
if ($this->exists($key)) {
$this->db->update('configurations', ['value' => $value], ['code' => $key]);
return;
}
// Insert it
$this->db->insert('configurations', ['code' => $key, 'value' => $value]);
}
示例13: save
/**
* @param Album $album
* @param int $id
* @return int The number of affected rows
*/
public function save(Album $album, $id = null)
{
$data = $album->getArrayCopy();
if (null === $id) {
return $this->db->insert('album', $data);
} else {
return $this->db->update('album', $data, ['id' => $id]);
}
}
示例14: save
/**
* @param PublishedPost $publishedPost
*
* @return void
*/
public function save(PublishedPost $publishedPost)
{
$data = ['title' => $publishedPost->title, 'content' => $publishedPost->content, 'category' => $publishedPost->category];
try {
$this->connection->insert('published_posts', array_merge($data, ['id' => $publishedPost->id]));
} catch (\Doctrine\DBAL\DBALException $e) {
$this->connection->update('published_posts', $data, ['id' => $publishedPost->id]);
}
}
示例15: insertRegisteredUser
private function insertRegisteredUser(UserRegistered $payload)
{
$data = [];
$data['userIdentifier'] = $payload->userIdentifier()->toString();
$data['username'] = $payload->username()->toString();
$data['hashedPassword'] = $payload->hashedPassword()->toString();
$data['at'] = $payload->at()->format('Y-m-d H:i:s');
$this->connection->insert($this->table, $data);
}