本文整理汇总了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;
}
示例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);
}
示例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));
}
}
示例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);
}
示例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()));
}
示例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;
}
示例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;
}
示例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;
}
示例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'));
}
示例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;
}