本文整理汇总了PHP中DB_DataObject::query方法的典型用法代码示例。如果您正苦于以下问题:PHP DB_DataObject::query方法的具体用法?PHP DB_DataObject::query怎么用?PHP DB_DataObject::query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DB_DataObject
的用法示例。
在下文中一共展示了DB_DataObject::query方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: process
function process()
{
// Start transaction
$db = new DB_DataObject();
$db->query('BEGIN');
// Get existing constituencies
$search = factory::create('search');
$results = $search->search("constituency", array(array("election_id", "=", $this->election_id)), 'AND', array(array("constituency_election", "inner")), array(array('name', "ASC")));
// Delete existing constituencies
foreach ($results as $result) {
if (!$result->delete()) {
$db->query('ROLLBACK');
die("Unable to delete constituency. Transaction rolled back.");
}
}
// Delete many-to-many joins
$query_string = 'DELETE FROM `constituency_election`
WHERE `election_id`=' . $this->election_id;
if ($db->query($query_string) === false) {
$db->query('ROLLBACK');
die("Unable to delete constituency links. Transaction rolled back.");
}
// Add user supplied constituencies
$supplied_constituencies = explode("\n", $this->data['txtConstituencies']);
foreach ($supplied_constituencies as $constituency_name) {
$constituency_name = trim($constituency_name);
if ($constituency_name == '') {
continue;
}
// Check for an existing constituency (from another election)
$existing_constituency = $search->search("constituency", array(array("name", "=", $constituency_name)));
if (count($existing_constituency) == 1) {
$constituency = $existing_constituency[0];
} else {
// Create constituency
$constituency = factory::create('constituency');
$constituency->name = $constituency_name;
if (!$constituency->insert()) {
$db->query('ROLLBACK');
die("Unable to add constituency. Transaction rolled back.");
}
}
// Create join
$constituency_election = factory::create('constituency_election');
$constituency_election->constituency_id = $constituency->constituency_id;
$constituency_election->election_id = $this->election_id;
if (!$constituency_election->insert()) {
$db->query('ROLLBACK');
die("Unable to add constituency. Transaction rolled back.");
}
}
$db->query('COMMIT');
$this->bind();
$this->render();
}
示例2: process
function process()
{
// Start transaction
$db = new DB_DataObject();
$db->query('BEGIN');
// Get existing mappings
$search = factory::create('search');
$results = $search->search("australian_postcode", array(array("election_id", "=", $this->election_id)));
// Delete existing mappings
foreach ($results as $result) {
if ($result->delete() === false) {
$db->query('ROLLBACK');
die("Unable to delete mapping. Transaction rolled back.");
}
}
// Add user supplied mappings
$supplied_mappings = explode("\n", $this->data['txtPostcodeMappings']);
foreach ($supplied_mappings as $mapping) {
$mapping = explode(',', $mapping);
$postcode = trim($mapping[0]);
// TODO: Sanity check postcode
$constituency = trim($mapping[1]);
if ($postcode == '' && $constituency == '') {
continue;
}
$australian_postcode = factory::create('australian_postcode');
$australian_postcode->election_id = $this->election_id;
$australian_postcode->postcode = $postcode;
$australian_postcode->constituency = $constituency;
if (!$australian_postcode->insert()) {
$db->query('ROLLBACK');
die("Unable to add mapping. Transaction rolled back.");
}
}
$db->query('COMMIT');
$this->bind();
$this->render();
}
示例3: showContent
function showContent()
{
$properties = ['id', 'nickname', 'fullname', 'profileurl', 'homepage', 'bio', 'location', 'lat', 'lon', 'location_id', 'location_ns', 'created', 'modified'];
// $config['staleaccounts']['inactive_period'] is number of months
// of inactivity before an account is considered stale.
// Defaults to 3
$inactive_period = common_config('staleaccounts', 'inactive_period') ?: 3;
// Calculate stale date (today - $inactive_period)
$stale_date = new DateTime();
$stale_date->modify('-' . $inactive_period . ' month');
$stale_date = $stale_date->format('Y-m-d');
$offset = ($this->page - 1) * PROFILES_PER_PAGE;
$limit = PROFILES_PER_PAGE + 1;
$dataObj = new DB_DataObject();
// Custom query because I only want to hit the db once
$dataObj->query('SELECT * FROM
(
SELECT local_profiles.*, MAX(n.created) as latest_activity FROM
(
SELECT p.*
FROM profile p
JOIN user u ON u.id = p.id
) local_profiles
LEFT JOIN notice n ON local_profiles.id = n.profile_id
GROUP BY local_profiles.id
ORDER BY latest_activity
) z
WHERE z.latest_activity < "' . $stale_date . '"
OR z.latest_activity IS NULL
LIMIT ' . $offset . ', ' . $limit . ';');
$cnt = $dataObj->N;
$this->elementStart('ul');
while ($dataObj->fetch()) {
$profile = new Profile();
foreach ($properties as $property) {
$profile->{$property} = $dataObj->{$property};
}
$profile->latest_activity = $dataObj->latest_activity;
$pli = new StaleProfileListItem($profile, $this);
$pli->show();
}
$this->elementEnd('ul');
$this->pagination($this->page > 1, $cnt > PROFILES_PER_PAGE, $this->page, 'staleaccounts', $this->args);
}
示例4: query
/**
* Execute a query by the current DAO, localizing it along the way (if needed).
*
* @param string $query
* The SQL query for execution.
* @param bool $i18nRewrite
* Whether to rewrite the query.
*
* @return object
* the current DAO object after the query execution
*/
public function query($query, $i18nRewrite = TRUE)
{
// rewrite queries that should use $dbLocale-based views for multi-language installs
global $dbLocale, $_DB_DATAOBJECT;
$conn =& $_DB_DATAOBJECT['CONNECTIONS'][$this->_database_dsn_md5];
$orig_options = $conn->options;
$this->_setDBOptions($this->_options);
if ($i18nRewrite and $dbLocale) {
$query = CRM_Core_I18n_Schema::rewriteQuery($query);
}
$ret = parent::query($query);
$this->_setDBOptions($orig_options);
return $ret;
}
示例5: query
/**
* Execute a query by the current DAO, localizing it along the way (if needed).
*
* @param string $query
* The SQL query for execution.
* @param bool $i18nRewrite
* Whether to rewrite the query.
*
* @return object
* the current DAO object after the query execution
*/
public function query($query, $i18nRewrite = TRUE)
{
// rewrite queries that should use $dbLocale-based views for multi-language installs
global $dbLocale;
if ($i18nRewrite and $dbLocale) {
$query = CRM_Core_I18n_Schema::rewriteQuery($query);
}
return parent::query($query);
}
示例6: query
/**
* Execute a query by the current DAO, localizing it along the way (if needed).
*
* @param string $query the SQL query for execution
* @param bool $i18nRewrite whether to rewrite the query
* @return object the current DAO object after the query execution
*/
function query($query, $i18nRewrite = true)
{
// rewrite queries that should use $dbLocale-based views for multi-language installs
global $dbLocale;
if ($i18nRewrite and $dbLocale) {
require_once 'CRM/Core/I18n/Schema.php';
$query = CRM_Core_I18n_Schema::rewriteQuery($query);
}
return parent::query($query);
}
示例7: query
function query($req)
{
$this->trigger('query', array($req));
return parent::query($req);
}