本文整理汇总了PHP中MongoCollection::execute方法的典型用法代码示例。如果您正苦于以下问题:PHP MongoCollection::execute方法的具体用法?PHP MongoCollection::execute怎么用?PHP MongoCollection::execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoCollection
的用法示例。
在下文中一共展示了MongoCollection::execute方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* Execute
*
* @param ParameterContainer|array $parameters
* @throws Exception\RuntimeException
* @return mixed
*/
public function execute($parameters = null)
{
if (!$this->isPrepared) {
$this->prepare();
}
/** START Standard ParameterContainer Merging Block */
if (!$this->parameterContainer instanceof ParameterContainer) {
if ($parameters instanceof ParameterContainer) {
$this->parameterContainer = $parameters;
$parameters = null;
} else {
$this->parameterContainer = new ParameterContainer();
}
}
if (is_array($parameters)) {
$this->parameterContainer->setFromArray($parameters);
}
if ($this->parameterContainer->count() > 0) {
$this->bindParametersFromContainer();
}
/** END Standard ParameterContainer Merging Block */
if ($this->profiler) {
$this->profiler->profilerStart($this);
}
if ($this->bufferResults === true) {
// $this -> resource -> store_result();
// $this -> isPrepared = false;
$buffered = true;
} else {
$buffered = false;
}
if ($this->sql instanceof \MongoZend\Db\NoSql\Select) {
$_order = $this->sql->getOrder();
// , $this -> sql->getColumns()
$return = $this->resource->find($this->sql->getWhere());
if (!empty($_order)) {
foreach ($_order as $_k => $_v) {
if (strtolower($_v) == 'desc' || $_v < 0) {
$_order[$_k] = -1;
} else {
$_order[$_k] = 1;
}
}
$return = $return->sort($_order);
}
if ($this->sql->getLimit() !== null) {
$return = $return->limit($this->sql->getLimit());
}
if ($this->sql->getOffset() !== null) {
$return = $return->skip($this->sql->getOffset());
}
} elseif ($this->sql instanceof \MongoZend\Db\NoSql\Insert) {
$_data = $this->sql->getValues();
$return = $this->resource->insert($_data);
$buffered = $this->sql->getRawState()['table'];
$this->driver->getConnection()->storeLastGeneratedValue($buffered, $_data['_id']);
// $return = $this -> resource -> update( [ '_id' => $_data[ '_id' ] ], [ '$set' => array( "id" => (string) $_data[ '_id' ] ) ] );
} elseif ($this->sql instanceof \MongoZend\Db\NoSql\Update) {
$_data = $this->sql->getSet();
$_where = $this->sql->getWhere();
$return = $this->resource->update($_where, $_data);
$buffered = $this->sql->getRawState()['table'];
$this->driver->getConnection()->storeLastGeneratedValue($buffered, $_data['_id']);
} elseif ($this->sql instanceof \MongoZend\Db\NoSql\Delete) {
$_where = $this->sql->getWhere();
$return = $this->resource->remove($_where);
$buffered = $this->sql->getRawState()['table'];
$this->driver->getConnection()->storeLastGeneratedValue($buffered, null);
} else {
$return = $this->resource->execute();
}
if ($this->profiler) {
$this->profiler->profilerFinish();
}
if ($return === false) {
throw new Exception\RuntimeException($this->getDriver()->getConnection()->getDB()->lastError());
}
$result = $this->driver->createResult($return, $buffered);
return $result;
}