本文整理汇总了PHP中xPDOQuery::prepare方法的典型用法代码示例。如果您正苦于以下问题:PHP xPDOQuery::prepare方法的具体用法?PHP xPDOQuery::prepare怎么用?PHP xPDOQuery::prepare使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xPDOQuery
的用法示例。
在下文中一共展示了xPDOQuery::prepare方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getResults
protected function getResults(xPDOQuery &$c)
{
$list = array();
$this->currentIndex = 0;
if ($c->prepare()) {
if ($c->stmt->execute()) {
while ($row = $c->stmt->fetch(PDO::FETCH_ASSOC)) {
$object_id = $row['object_id'];
if (empty($list[$object_id])) {
$list[$object_id] = $row;
$list[$object_id]['tvs'] = array();
$this->currentIndex++;
}
if (!empty($row['tv_name'])) {
$list[$object_id]['tvs'][$row['tv_name']] = array('tv_id' => $row['tv_id'], 'caption' => $row['tv_caption'], 'category' => $row['tv_category'], 'value_id' => $row['tv_value_id'], 'value' => $row['tv_value']);
}
}
} else {
if ($c->stmt->errorCode() !== "00000") {
$this->modx->log(xPDO::LOG_LEVEL_ERROR, __CLASS__);
$this->modx->log(xPDO::LOG_LEVEL_ERROR, print_r($c->stmt->errorInfo(), true));
$this->modx->log(xPDO::LOG_LEVEL_ERROR, $c->toSQL());
}
}
}
return $list;
}
示例2: prepareQueryBeforeCount
/**
* @param xPDOQuery $c
*
* @return xPDOQuery
*/
public function prepareQueryBeforeCount(xPDOQuery $c)
{
$c->leftJoin('modMediaSource', 'Source');
$c->leftJoin($this->classKey, 'Thumb', "`{$this->classKey}`.`id` = `Thumb`.`parent`");
$c->groupby($this->classKey . '.id');
$c->select('`Source`.`name` as `source_name`');
$c->select('`Thumb`.`url` as `thumbnail`');
$c->where(array('resource_id' => $this->getProperty('resource_id')));
$parent = $this->getProperty('parent');
if ($parent !== false) {
$c->where(array('parent' => $parent));
}
$query = trim($this->getProperty('query'));
if (!empty($query)) {
$c->where(array('file:LIKE' => "%{$query}%", 'OR:name:LIKE' => "%{$query}%", 'OR:alt:LIKE' => "%{$query}%", 'OR:description:LIKE' => "%{$query}%", 'OR:add:LIKE' => "%{$query}%"));
}
$tags = array_map('trim', explode(',', $this->getProperty('tags')));
if (!empty($tags[0])) {
$tags = implode("','", $tags);
$c->innerJoin('msResourceFileTag', 'Tag', "`{$this->classKey}`.`id` = `Tag`.`file_id` AND `Tag`.`tag` IN ('" . $tags . "')");
$c->groupby($this->classKey . '.id');
$c->prepare();
$this->modx->log(1, $c->toSQL());
}
return $c;
}
示例3: prepareQuery
/**
* Set parameters and prepare query
*
* @return PDOStatement
*/
public function prepareQuery()
{
if (!empty($this->config['limit'])) {
$time = microtime(true);
$this->query->limit($this->config['limit'], $this->config['offset']);
$this->addTime('Limited to <b>' . $this->config['limit'] . '</b>, offset <b>' . $this->config['offset'] . '</b>', microtime(true) - $time);
}
return $this->query->prepare();
}
示例4: prepareQuery
/**
* Set parameters and prepare query
*
* @return PDOStatement
*/
public function prepareQuery()
{
if ($limit = (int) $this->config['limit']) {
$offset = (int) $this->config['offset'];
$time = microtime(true);
$this->query->limit($limit, $offset);
$this->addTime('Limited to <b>' . $limit . '</b>, offset <b>' . $offset . '</b>', microtime(true) - $time);
}
return $this->query->prepare();
}
示例5: countTotal
protected function countTotal($className, xPDOQuery &$query)
{
if (!$query->prepare()) {
return false;
}
$sql = "SELECT count(*) as count FROM (" . $query->toSQL() . ") as t;";
if (!($stmt = $this->modx->prepare($sql)) or !$stmt->execute()) {
return false;
}
return current((array) $stmt->fetch(PDO::FETCH_NUM));
}
示例6: getResults
protected function getResults(xPDOQuery &$c)
{
$list = array();
$this->currentIndex = 0;
if ($c->prepare() && $c->stmt->execute()) {
while ($row = $c->stmt->fetch(PDO::FETCH_ASSOC)) {
$object_id = $row['object_id'];
if (empty($list[$object_id])) {
$list[$object_id] = $row;
$this->currentIndex++;
}
}
}
return $list;
}
示例7: rewindOriginal
/**
*
*/
public function rewindOriginal()
{
$this->index = 0;
if (!empty($this->stmt)) {
$this->stmt->closeCursor();
}
$this->stmt = $this->criteria->prepare();
$tstart = microtime(true);
if ($this->stmt && $this->stmt->execute()) {
$this->xpdo->queryTime += microtime(true) - $tstart;
$this->xpdo->executedQueries++;
$this->fetch();
} elseif ($this->stmt) {
$this->xpdo->queryTime += microtime(true) - $tstart;
$this->xpdo->executedQueries++;
}
}
示例8: prepareQueryBeforeCount
public function prepareQueryBeforeCount(xPDOQuery $c)
{
$form = $this->getProperty('form');
if (!empty($form)) {
$c->andCondition(array('form' => $form));
}
$context_key = $this->getProperty('context_key');
if (!empty($context_key)) {
$c->andCondition(array('context_key' => $context_key));
}
$startDate = $this->getProperty('startDate');
if ($startDate != '') {
$c->andCondition(array('date:>' => strtotime($startDate . ' 00:00:00')));
}
$endDate = $this->getProperty('endDate');
if ($endDate != '') {
$c->andCondition(array('date:<' => strtotime($endDate . ' 23:59:59')));
}
$c->prepare();
return $c;
}
示例9: niceQuery
/**
* Returns select statement for easy reading
*
* @access public
* @param xPDOQuery $query The query to print
* @return string The select statement
* @author Coroico <coroico@wangba.fr>
*/
public function niceQuery(xPDOQuery $query = null)
{
$searched = array("SELECT", "GROUP_CONCAT", "LEFT JOIN", "INNER JOIN", "EXISTS", "LIMIT", "FROM", "WHERE", "GROUP BY", "HAVING", "ORDER BY", "OR", "AND", "IFNULL", "ON", "MATCH", "AGAINST", "COUNT");
$replace = array(" \r\nSELECT", " \r\nGROUP_CONCAT", " \r\nLEFT JOIN", " \r\nINNER JOIN", " \r\nEXISTS", " \r\nLIMIT", " \r\nFROM", " \r\nWHERE", " \r\nGROUP BY", " \r\nHAVING", " ORDER BY", " \r\nOR", " \r\nAND", " \r\nIFNULL", " \r\nON", " \r\nMATCH", " \r\nAGAINST", " \r\nCOUNT");
$output = '';
if (isset($query)) {
$query->prepare();
$output = str_replace($searched, $replace, " " . $query->toSQL());
}
return $output;
}
示例10: prepareQueryAfterCount
public function prepareQueryAfterCount(xPDOQuery $c)
{
$c->prepare();
$this->modx->log(modX::LOG_LEVEL_ERROR, $c->toSql());
return $c;
}
示例11: niceQuery
/**
* Returns select statement for easy reading.
*
* @param xPDOQuery $query The query to print
*
* @return string The select statement
*
* @author Coroico <coroico@wangba.fr>
*/
public function niceQuery(xPDOQuery $query = null)
{
$searched = array('SELECT', 'GROUP_CONCAT', 'LEFT JOIN', 'INNER JOIN', 'EXISTS', 'LIMIT', 'FROM', 'WHERE', 'GROUP BY', 'HAVING', 'ORDER BY', 'OR', 'AND', 'IFNULL', 'ON', 'MATCH', 'AGAINST', 'COUNT');
$replace = array(" \r\nSELECT", " \r\nGROUP_CONCAT", " \r\nLEFT JOIN", " \r\nINNER JOIN", " \r\nEXISTS", " \r\nLIMIT", " \r\nFROM", " \r\nWHERE", " \r\nGROUP BY", " \r\nHAVING", ' ORDER BY', " \r\nOR", " \r\nAND", " \r\nIFNULL", " \r\nON", " \r\nMATCH", " \r\nAGAINST", " \r\nCOUNT");
$output = '';
if (isset($query)) {
$query->prepare();
$output = str_replace($searched, $replace, ' ' . $query->toSQL());
}
return $output;
}