當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Insert::columns方法代碼示例

本文整理匯總了PHP中Zend\Db\Sql\Insert::columns方法的典型用法代碼示例。如果您正苦於以下問題:PHP Insert::columns方法的具體用法?PHP Insert::columns怎麽用?PHP Insert::columns使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Zend\Db\Sql\Insert的用法示例。


在下文中一共展示了Insert::columns方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: insertSession

 public function insertSession($username, $password, $session_id)
 {
     $insert = new Insert('sessions');
     $adapter = $this->table_gateway->getAdapter();
     $insert->columns(array('username', 'password', 'active', 'session_id'))->values(array('username' => $username, 'password' => $password, 'active' => 1, 'session_id' => $session_id));
     $adapter->query($this->sql->buildSqlString($insert), $adapter::QUERY_MODE_EXECUTE);
     return true;
 }
開發者ID:ponchov,項目名稱:teeforall,代碼行數:8,代碼來源:LoginModel.php

示例2: insertPrivilege

 public function insertPrivilege($attributes)
 {
     $attributes = $this->verifyPrivilege($attributes);
     $status_id = isset($attributes['status_id']) ? $attributes['status_id'] : 0;
     $insert = new Insert($this->getTable());
     $insert->columns(array('table_name', 'permissions', 'group_id'))->values(array('table_name' => $attributes['table_name'], 'permissions' => $attributes['permissions'], 'group_id' => $attributes['group_id'], 'status_id' => $status_id));
     $this->insertWith($insert);
     $privilegeId = $this->lastInsertValue;
     return $this->fetchById($privilegeId);
 }
開發者ID:rudderdon,項目名稱:Directus,代碼行數:10,代碼來源:DirectusPrivilegesTableGateway.php

示例3: preInsert

 /**
  * @param Insert $insert
  */
 public function preInsert(Insert $insert)
 {
     $metaColumns = $this->tableGateway->getColumns();
     if (count($metaColumns)) {
         $metaColumns = array_flip($metaColumns);
         $columns = array_flip($insert->getRawState('columns'));
         $columns = array_flip(array_intersect_key($columns, $metaColumns));
         $values = $insert->getRawState('values');
         $values = array_intersect_key($values, $columns);
         $insert->values(array_values($values));
         $insert->columns(array_values($columns));
     }
 }
開發者ID:zfstarter,項目名稱:zfs-domain-model,代碼行數:16,代碼來源:FilterColumnsFeature.php

示例4: insertPrivilege

 public function insertPrivilege($attributes)
 {
     $attributes = $this->verifyPrivilege($attributes);
     // @todo: this should fallback on field default value
     if (!isset($attributes['status_id'])) {
         $attributes['status_id'] = 0;
     }
     $attributes = $this->getFillableFields($attributes);
     $insert = new Insert($this->getTable());
     $insert->columns(array_keys($attributes))->values($attributes);
     $this->insertWith($insert);
     $privilegeId = $this->lastInsertValue;
     return $this->fetchById($privilegeId);
 }
開發者ID:hyrmedia,項目名稱:directus,代碼行數:14,代碼來源:DirectusPrivilegesTableGateway.php

示例5: testGetSqlString

 /**
  * @covers Zend\Db\Sql\Insert::getSqlString
  */
 public function testGetSqlString()
 {
     $this->insert->into('foo')->values(array('bar' => 'baz', 'boo' => new Expression('NOW()'), 'bam' => null));
     $this->assertEquals('INSERT INTO "foo" ("bar", "boo", "bam") VALUES (\'baz\', NOW(), NULL)', $this->insert->getSqlString(new TrustingSql92Platform()));
     // with TableIdentifier
     $this->insert = new Insert();
     $this->insert->into(new TableIdentifier('foo', 'sch'))->values(array('bar' => 'baz', 'boo' => new Expression('NOW()'), 'bam' => null));
     $this->assertEquals('INSERT INTO "sch"."foo" ("bar", "boo", "bam") VALUES (\'baz\', NOW(), NULL)', $this->insert->getSqlString(new TrustingSql92Platform()));
     // with Select
     $this->insert = new Insert();
     $select = new Select();
     $this->insert->into('foo')->select($select->from('bar'));
     $this->assertEquals('INSERT INTO "foo"  SELECT "bar".* FROM "bar"', $this->insert->getSqlString(new TrustingSql92Platform()));
     // with Select and columns
     $this->insert->columns(array('col1', 'col2'));
     $this->assertEquals('INSERT INTO "foo" ("col1", "col2") SELECT "bar".* FROM "bar"', $this->insert->getSqlString(new TrustingSql92Platform()));
 }
開發者ID:pnaq57,項目名稱:zf2demo,代碼行數:20,代碼來源:InsertTest.php

示例6: preInsert

 public function preInsert(Insert $insert)
 {
     $columns = $insert->getRawState('columns');
     $values = $insert->getRawState('values');
     $key = array_search($this->primaryKeyField, $columns);
     if ($key !== false) {
         $this->sequenceValue = $values[$key];
         return $insert;
     }
     $this->sequenceValue = $this->nextSequenceId();
     if ($this->sequenceValue === null) {
         return $insert;
     }
     array_push($columns, $this->primaryKeyField);
     array_push($values, $this->sequenceValue);
     $insert->columns($columns);
     $insert->values($values);
     return $insert;
 }
開發者ID:Yansor,項目名稱:yafblog,代碼行數:19,代碼來源:SequenceFeature.php

示例7: sendMessage

 public function sendMessage($payload, $recipients, $from)
 {
     $defaultValues = ['response_to' => null];
     $payload = array_merge($defaultValues, $payload);
     $insert = new Insert($this->getTable());
     $insert->columns(['from', 'subject', 'message'])->values(['from' => $from, 'subject' => $payload['subject'], 'message' => $payload['message'], 'datetime' => DateUtils::now(), 'response_to' => $payload['response_to']]);
     $rows = $this->insertWith($insert);
     $messageId = $this->lastInsertValue;
     // Insert recipients
     $values = [];
     foreach ($recipients as $recipient) {
         $read = 0;
         if ((int) $recipient == (int) $from) {
             $read = 1;
         }
         $values[] = '(' . $messageId . ', ' . $recipient . ', ' . $read . ')';
     }
     $valuesString = implode(',', $values);
     //@todo sanitize and implement ACL
     $sql = 'INSERT INTO directus_messages_recipients (`message_id`, `recipient`, `read`) VALUES ' . $valuesString;
     $result = $this->adapter->query($sql, Adapter::QUERY_MODE_EXECUTE);
     return $messageId;
 }
開發者ID:YounessTayer,項目名稱:directus,代碼行數:23,代碼來源:DirectusMessagesTableGateway.php

示例8: sendMessage

 public function sendMessage($payload, $recipients, $from)
 {
     $defaultValues = array('response_to' => null);
     $payload = array_merge($defaultValues, $payload);
     $insert = new Insert($this->getTable());
     $insert->columns(array('from', 'subject', 'message'))->values(array('from' => $from, 'subject' => $payload['subject'], 'message' => $payload['message'], 'datetime' => gmdate("Y-m-d H:i:s"), 'response_to' => $payload['response_to']));
     $rows = $this->insertWith($insert);
     $messageId = $this->lastInsertValue;
     // Insert recipients
     $values = array();
     foreach ($recipients as $recipient) {
         $read = 0;
         if ((int) $recipient == (int) $from) {
             $read = 1;
         }
         $values[] = "({$messageId}, {$recipient}, {$read})";
     }
     $valuesString = implode(',', $values);
     //@todo sanitize and implement ACL
     $sql = "INSERT INTO directus_messages_recipients (`message_id`, `recipient`, `read`) VALUES {$valuesString}";
     $result = $this->adapter->query($sql, Adapter::QUERY_MODE_EXECUTE);
     return $messageId;
 }
開發者ID:hyrmedia,項目名稱:directus,代碼行數:23,代碼來源:DirectusMessagesTableGateway.php

示例9: testColumns

 /**
  * @covers Zend\Db\Sql\Insert::columns
  */
 public function testColumns()
 {
     $this->insert->columns(array('foo', 'bar'));
     $this->assertEquals(array('foo', 'bar'), $this->readAttribute($this->insert, 'columns'));
 }
開發者ID:Rovak,項目名稱:zf2,代碼行數:8,代碼來源:InsertTest.php

示例10: index05Action

 public function index05Action()
 {
     $table = "user";
     $adapter = $this->getServiceLocator()->get("db_books");
     $tableGateway = new TableGateway($table, $adapter);
     $insertObj = new Insert("user");
     $insertObj->columns(array("name", "email"))->values(array("name" => "Armasky", "email" => "ak@hotmail.com"));
     $tableGateway->insertWith($insertObj);
     //last record inserted
     echo $tableGateway->getLastInsertValue();
     return false;
 }
開發者ID:trongle,項目名稱:zend-2,代碼行數:12,代碼來源:TableGatewayController.php


注:本文中的Zend\Db\Sql\Insert::columns方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。