本文整理汇总了PHP中MDB2_Driver_Common::queryOne方法的典型用法代码示例。如果您正苦于以下问题:PHP MDB2_Driver_Common::queryOne方法的具体用法?PHP MDB2_Driver_Common::queryOne怎么用?PHP MDB2_Driver_Common::queryOne使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MDB2_Driver_Common
的用法示例。
在下文中一共展示了MDB2_Driver_Common::queryOne方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
function execute($aParams)
{
$this->oUpgrade =& $aParams[0];
$this->oDbh =& OA_DB::singleton();
$aConf = $GLOBALS['_MAX']['CONF']['table'];
$prefix = $aConf['prefix'];
foreach (array('tblAppVar' => 'application_variable', 'tblAccounts' => 'accounts', 'tblAgency' => 'agency', 'tblClients' => 'clients', 'tblCampaigns' => 'campaigns', 'tblBanners' => 'banners', 'tblAcls' => 'acls', 'tblPrefs' => 'preferences', 'tblAccPrefs' => 'account_preference_assoc') as $k => $v) {
${$k} = $this->oDbh->quoteIdentifier($prefix . ($aConf[$v] ? $aConf[$v] : $v), true);
}
// Get admin account ID
$adminAccountId = (int) $this->oDbh->queryOne("SELECT value FROM {$tblAppVar} WHERE name = 'admin_account_id'");
if (PEAR::isError($adminAccountId)) {
$this->logError("No admin account ID");
return false;
}
// Get preference ID for timezone
$tzId = $this->oDbh->queryOne("SELECT preference_id FROM {$tblPrefs} WHERE preference_name = 'timezone'");
if (empty($tzId) || PEAR::isError($tzId)) {
// Upgrading from 2.4 maybe?
$tzId = 0;
$this->logOnly("No timezone preference available, using default server timezone");
$adminTz = date_default_timezone_get();
if (empty($adminTz)) {
// C'mon you should have set the timezone in your php.ini!
$this->logOnly("No default server timezone, using UTC");
$adminTz = 'UTC';
}
} else {
// Get admin timezone
$adminTz = $this->oDbh->queryOne("SELECT value FROM {$tblAccPrefs} WHERE preference_id = {$tzId} AND account_id = {$adminAccountId}");
if (empty($adminTz) || PEAR::isError($adminTz)) {
$this->logOnly("No admin timezone, using UTC");
$adminTz = 'UTC';
}
}
$joinList = "{$tblBanners} b JOIN\n {$tblCampaigns} ca USING (campaignid) JOIN\n {$tblClients} cl USING (clientid) JOIN\n {$tblAgency} a USING (agencyid) LEFT JOIN\n {$tblAccPrefs} p ON (p.account_id = a.account_id AND p.preference_id = {$tzId})";
$tzPart = "COALESCE(p.value, " . $this->oDbh->quote($adminTz) . ")";
$wherePart = "\n ac.bannerid = b.bannerid AND\n \tac.type LIKE 'deliveryLimitations:Time:%' AND\n \tac.data NOT LIKE '%@%'\n ";
if ($this->oDbh->dbsyntax == 'pgsql') {
$query = "\n UPDATE\n {$tblAcls} ac\n SET\n data = data || '@' || {$tzPart}\n FROM\n {$joinList}\n WHERE\n {$wherePart}\n ";
} else {
$query = "\n UPDATE\n {$tblAcls} ac,\n {$joinList}\n SET\n ac.data = CONCAT(ac.data, '@', {$tzPart})\n WHERE\n {$wherePart}\n ";
}
$ret = $this->oDbh->exec($query);
if (PEAR::isError($ret)) {
$this->logError($ret->getUserInfo());
return false;
}
// Rebuild ACLs
$this->oUpgrade->addPostUpgradeTask('Recompile_Acls');
// Also rebuild banner cache for OX-5184
$this->oUpgrade->addPostUpgradeTask('Rebuild_Banner_Cache');
$this->logOnly("Appended timezone information to {$ret} time based delivery limitations");
return true;
}
示例2: testDeleteSession
function testDeleteSession()
{
$this->generateSession();
$this->dalSession->deleteSession(SESSIONID);
$prefix = OA_Dal::getTablePrefix();
$table = $this->dbh->quoteIdentifier($prefix . 'session');
$cSessions = $this->dbh->queryOne("SELECT count(*) AS c FROM {$table}");
$this->assertEqual(0, $cSessions);
}
示例3: getDocumentType
/**
* Gets the identifier of a document type by the type's shortname
*
* @param MDB2_Driver_Common $db the database driver to use to get the
* document type identifier.
* @param string $type_shortname the shortname of the document type.
*
* @return integer the document type identifier of the type or null if no
* such type exists.
*
* @throws NateGoSearchDBException if a database error occurs.
*/
public static function getDocumentType(MDB2_Driver_Common $db, $type_shortname)
{
$type_shortname = (string) $type_shortname;
$sql = sprintf('select id from NateGoSearchType
where shortname = %s', $db->quote($type_shortname, 'text'));
$type = $db->queryOne($sql);
if (MDB2::isError($type)) {
throw new NateGoSearchDBException($type);
}
return $type;
}
示例4: checkForUpdates
/**
* Connect to OpenX Sync to check for updates
*
* @param float $already_seen Only check for updates newer than this value.
* @return array An array of two items:
*
* Item 0 is the XML-RPC error code. Meanings:
* -2 => The admin user has disabled update checking
* -1 => No response from the server
* 0 - 799 => XML-RPC library error codes
* 0 => No error
* 800 => No updates
* 801+ => Error codes from the remote XML-RPC server
*
* Item 1 is either the error message (item 1 != 0), or an array containing update info
*/
function checkForUpdates($already_seen = 0)
{
global $XML_RPC_erruser;
if (!$this->aConf['sync']['checkForUpdates']) {
// Checking for updates has been disabled by the admin user,
// so do not communicate with the server that provides the
// details of what upgrades are available - just return an
// 800 "error"
$aReturn = array(-2, 'Check for updates has been disabled by the administrator.');
return $aReturn;
}
// Create the XML-RPC client object
$client = OA_Central::getXmlRpcClient($this->_conf);
// Prepare the installation's platform hash
$platform_hash = OA_Dal_ApplicationVariables::get('platform_hash');
if (!$platform_hash) {
// The installation does not have a platform hash; generate one,
// and save it to the database for later use
OA::debug("Generating a new platform_hash for the installation", PEAR_LOG_INFO);
$platform_hash = OA_Dal_ApplicationVariables::generatePlatformHash();
if (!OA_Dal_ApplicationVariables::set('platform_hash', $platform_hash)) {
OA::debug("Could not save the new platform_hash to the database", PEAR_LOG_ERR);
unset($platform_hash);
OA::debug("Sync process proceeding without a platform_hash", PEAR_LOG_INFO);
}
}
// Prepare the parameters required for the XML-RPC call to
// obtain if an update is available for this installation
$params = array(new XML_RPC_Value(PRODUCT_NAME, 'string'), new XML_RPC_Value($this->getConfigVersion(OA_Dal_ApplicationVariables::get('oa_version')), 'string'), new XML_RPC_Value($already_seen, 'string'), new XML_RPC_Value($platform_hash, 'string'));
// Has the Revive Adserver admin user kindly agreed to share the
// technology stack that it is running on, to help the community?
$aTechStack = array('data' => false);
if ($this->aConf['sync']['shareStack']) {
// Thanks, admin user! You're a star! Prepare the technology stack
// data and add it to the XML-RPC call
if ($this->oDbh->dbsyntax == 'mysql') {
$dbms = 'MySQL';
} else {
if ($this->oDbh->dbsyntax == 'pgsql') {
$dbms = 'PostgreSQL';
} else {
$dbms = 'UnknownSQL';
}
}
$aTechStack = array('os_type' => php_uname('s'), 'os_version' => php_uname('r'), 'webserver_type' => isset($_SERVER['SERVER_SOFTWARE']) ? preg_replace('#^(.*?)/.*$#', '$1', $_SERVER['SERVER_SOFTWARE']) : '', 'webserver_version' => isset($_SERVER['SERVER_SOFTWARE']) ? preg_replace('#^.*?/(.*?)(?: .*)?$#', '$1', $_SERVER['SERVER_SOFTWARE']) : '', 'db_type' => $dbms, 'db_version' => $this->oDbh->queryOne("SELECT VERSION()"), 'php_version' => phpversion(), 'php_sapi' => ucfirst(php_sapi_name()), 'php_extensions' => get_loaded_extensions(), 'php_register_globals' => (bool) ini_get('register_globals'), 'php_magic_quotes_gpc' => (bool) ini_get('magic_quotes_gpc'), 'php_safe_mode' => (bool) ini_get('safe_mode'), 'php_open_basedir' => (bool) strlen(ini_get('open_basedir')), 'php_upload_tmp_readable' => (bool) is_readable(ini_get('upload_tmp_dir') . DIRECTORY_SEPARATOR));
}
$params[] = XML_RPC_Encode($aTechStack);
// Add the registered email address
$params[] = new XML_RPC_Value(OA_Dal_ApplicationVariables::get('sync_registered_email'), 'string');
// Create the XML-RPC request message
$msg = new XML_RPC_Message("Revive.Sync", $params);
// Send the XML-RPC request message
if ($response = $client->send($msg, 10)) {
// XML-RPC server found, now checking for errors
if (!$response->faultCode()) {
// No fault! Woo! Get the response and return it!
$aReturn = array(0, XML_RPC_Decode($response->value()));
// Prepare cache
$cache = $aReturn[1];
// Update last run
OA_Dal_ApplicationVariables::set('sync_last_run', date('Y-m-d H:i:s'));
// Also write to the debug log
OA::debug("Sync: updates found!", PEAR_LOG_INFO);
} else {
// Boo! An error! (Well, maybe - if it's 800, yay!)
$aReturn = array($response->faultCode(), $response->faultString());
// Prepare cache
$cache = false;
// Update last run
if ($response->faultCode() == 800) {
// Update last run
OA_Dal_ApplicationVariables::set('sync_last_run', date('Y-m-d H:i:s'));
// Also write to the debug log
OA::debug("Sync: {$aReturn[1]}", PEAR_LOG_INFO);
} else {
// Write to the debug log
OA::debug("Sync: {$aReturn[1]} (code: {$aReturn[0]}", PEAR_LOG_ERR);
// Return immediately without writing to cache
return $aReturn;
}
}
OA_Dal_ApplicationVariables::set('sync_cache', serialize($cache));
OA_Dal_ApplicationVariables::set('sync_timestamp', time());
return $aReturn;
//.........这里部分代码省略.........
示例5: commit
/**
* Commits keywords indexed by this indexer to the database index table
*
* If this indexer was created with the <code>$new</code> parameter then
* the index is cleared for this indexer's document type before new
* keywords are inserted. Otherwise, the new keywords are simply appended
* to the existing index.
*/
public function commit()
{
try {
$this->db->beginTransaction();
if ($this->new) {
$this->clear();
$this->new = false;
}
$indexed_ids = $this->db->implodeArray($this->clear_document_ids, 'integer');
$delete_sql = sprintf('delete from NateGoSearchIndex
where document_id in (%s) and document_type = %s', $indexed_ids, $this->db->quote($this->document_type, 'integer'));
$result = $this->db->exec($delete_sql);
if (MDB2::isError($result)) {
throw new NateGoSearchDBException($result);
}
$keyword = array_pop($this->keywords);
while ($keyword !== null) {
$sql = sprintf('insert into NateGoSearchIndex (
document_id,
document_type,
field_id,
word,
weight,
location
) values (%s, %s, %s, %s, %s, %s)', $this->db->quote($keyword->getDocumentId(), 'integer'), $this->db->quote($keyword->getDocumentType(), 'integer'), $this->db->quote($keyword->getTermId(), 'integer'), $this->db->quote($keyword->getWord(), 'text'), $this->db->quote($keyword->getWeight(), 'integer'), $this->db->quote($keyword->getLocation(), 'integer'));
$result = $this->db->exec($sql);
if (MDB2::isError($result)) {
throw new NateGoSearchDBException($result);
}
unset($keyword);
$keyword = array_pop($this->keywords);
}
$popular_keyword = array_pop($this->popular_keywords);
while ($popular_keyword !== null) {
// TODO: there must be a better way to handle dupe words...
$sql = sprintf('select count(keyword) from NateGoSearchPopularKeywords
where keyword = %s', $this->db->quote($popular_keyword, 'text'));
$exists = $this->db->queryOne($sql);
if (MDB2::isError($result)) {
throw new NateGoSearchDBException($result);
}
if (!$exists) {
$sql = sprintf('insert into NateGoSearchPopularKeywords
(keyword) values (%s)', $this->db->quote($popular_keyword, 'text'));
$result = $this->db->exec($sql);
if (MDB2::isError($result)) {
throw new NateGoSearchDBException($result);
}
}
unset($popular_keyword);
$popular_keyword = array_pop($this->popular_keywords);
}
$this->clear_document_ids = array();
$this->db->commit();
} catch (NateGoSearchDBException $e) {
$this->db->rollback();
throw $e;
}
}
示例6: query
/**
* Queries the NateGoSearch index with a set of keywords
*
* Querying does not directly return a set of results. This is due to the
* way NateGoSearch is designed. The document ids from this search are
* stored in a results table and accessed through a unique identifier.
*
* @param string $keywords the search string to query.
*
* @return NateGoSearchResult an object containing result information.
*
* @see NateGoSearchResult::getUniqueId()
*/
public function query($keywords)
{
static $unique_counter = 0;
$id = sha1(uniqid($unique_counter, true));
$keywords = $this->normalizeKeywordsForSpelling($keywords);
if ($this->spell_checker === null) {
$misspellings = array();
} else {
$misspellings = $this->spell_checker->getMisspellingsInPhrase($keywords);
}
$misspellings = $this->getPopularReplacements($keywords, $misspellings);
$keywords = $this->normalizeKeywordsForSearching($keywords);
$keywords_hash = sha1($keywords);
$results = new NateGoSearchResult($this->db, $id, $keywords, $this->document_types);
$results->addMisspellings($misspellings);
$searched_keywords = array();
$keyword = strtok($keywords, ' ');
while ($keyword) {
if (in_array($keyword, $this->blocked_words)) {
$results->addBlockedWords($keyword);
} else {
$searched_keywords[] = NateGoSearchIndexer::stemKeyword($keyword);
$results->addSearchedWords($keyword);
}
$keyword = strtok(' ');
}
$keywords = implode(' ', $searched_keywords);
if (count($this->document_types) > 0) {
$this->db->loadModule('Function');
$params = array($this->db->quote($keywords, 'text'), $this->db->quote($keywords_hash, 'text'), $this->quoteArray($this->document_types), $this->db->quote($id, 'text'));
$types = array('text');
$rs = $this->db->function->executeStoredProc('nateGoSearch', $params, $types);
if (MDB2::isError($rs)) {
throw new NateGoSearchDBException($rs);
}
$unique_id = $rs->fetchOne();
if (MDB2::isError($unique_id)) {
throw new NateGoSearchDBException($unique_id);
}
$unique_counter++;
$results->setUniqueId($unique_id);
$sql = sprintf('select count(document_id) from %s
where unique_id = %s', $results->getResultTable(), $this->db->quote($unique_id, 'text'));
$document_count = $this->db->queryOne($sql);
if (MDB2::isError($document_count)) {
throw new NateGoSearchDBException($document_count);
}
$results->setDocumentCount($document_count);
}
return $results;
}
示例7: checkForUpdates
/**
* Connect to OpenX Sync to check for updates
*
* @param float $already_seen Only check for updates newer than this value.
* @return array An array of two items:
*
* Item 0 is the XML-RPC error code. Meanings:
* -2 => The admin user has disabled update checking
* -1 => No response from the server
* 0 - 799 => XML-RPC library error codes
* 0 => No error
* 800 => No updates
* 801+ => Error codes from the remote XML-RPC server
*
* Item 1 is either the error message (item 1 != 0), or an array containing update info
*/
function checkForUpdates($already_seen = 0)
{
global $XML_RPC_erruser;
if (!$this->aConf['sync']['checkForUpdates']) {
// Checking for updates has been disabled by the admin user,
// so do not communicate with the OpenX server that provides
// the details of what upgrades are available - just return
// an 800 "error"
$aReturn = array(-2, 'Check for updates has been disabled by the OpenX administrator.');
return $aReturn;
}
// Should this server's technology stack be shared with OpenX?
$shareTechStack = false;
if ($this->aConf['sync']['shareStack']) {
$shareTechStack = true;
}
// Should this server's aggregate impression and click statistcs
// be shared with OpenX?
$shareStats = false;
if ($this->aConf['sync']['shareData']) {
$shareStats = true;
}
// Create the XML-RPC client object
$client = OA_Central::getXmlRpcClient($this->_conf);
// Prepare the parameters required for the XML-RPC call to
// obtain if an update is available for this OpenX installation
$params = array(new XML_RPC_Value(MAX_PRODUCT_NAME, 'string'), new XML_RPC_Value($this->getConfigVersion(OA_Dal_ApplicationVariables::get('oa_version')), 'string'), new XML_RPC_Value($already_seen, 'string'), new XML_RPC_Value('', 'string'), new XML_RPC_Value(OA_Dal_ApplicationVariables::get('platform_hash'), 'string'));
// Has the OpenX admin user kindly agreed to share the technology
// stack that OpenX is running on, so that OpenX can monitor what
// technology stacks the community users, to help with supporting
// OpenX?
$aTechStack = array('data' => false);
if ($shareTechStack) {
// Thanks, OpenX admin user! You're a star! Prepare the
// technology stack data and add it to the XML-RPC call
if ($this->oDbh->dbsyntax == 'mysql') {
$dbms = 'MySQL';
} else {
if ($this->oDbh->dbsyntax == 'pgsql') {
$dbms = 'PostgreSQL';
} else {
$dbms = 'UnknownSQL';
}
}
$aTechStack = array('os_type' => php_uname('s'), 'os_version' => php_uname('r'), 'webserver_type' => isset($_SERVER['SERVER_SOFTWARE']) ? preg_replace('#^(.*?)/.*$#', '$1', $_SERVER['SERVER_SOFTWARE']) : '', 'webserver_version' => isset($_SERVER['SERVER_SOFTWARE']) ? preg_replace('#^.*?/(.*?)(?: .*)?$#', '$1', $_SERVER['SERVER_SOFTWARE']) : '', 'db_type' => $dbms, 'db_version' => $this->oDbh->queryOne("SELECT VERSION()"), 'php_version' => phpversion(), 'php_sapi' => ucfirst(php_sapi_name()), 'php_extensions' => get_loaded_extensions(), 'php_register_globals' => (bool) ini_get('register_globals'), 'php_magic_quotes_gpc' => (bool) ini_get('magic_quotes_gpc'), 'php_safe_mode' => (bool) ini_get('safe_mode'), 'php_open_basedir' => (bool) strlen(ini_get('open_basedir')), 'php_upload_tmp_readable' => (bool) is_readable(ini_get('upload_tmp_dir') . DIRECTORY_SEPARATOR));
}
$params[] = XML_RPC_Encode($aTechStack);
// Has the OpenX admin user kindly agreed to share their
// aggregate impression and click statistics to help
// OpenX monitor what sizes of OpenX installations exist
// (to ensure OpenX scales to appropriate sizes), and also
// so that the total community size can be shown in the
// Dashboard?
$aStats = array();
if ($shareStats) {
// Thanks, OpenX admin user! You're a star! Prepare the
// aggregate impression and click statistics data and
// add it to the XML-RPC call
foreach ($this->buildStats() as $k => $v) {
$aStats[$k] = XML_RPC_encode($v);
}
}
$params[] = new XML_RPC_Value($aStats, 'struct');
// Add the OpenX package Origin ID, if appropriate
$originID = '';
$originFile = MAX_PATH . '/etc/origin.txt';
if (file_exists($originFile) && is_readable($originFile)) {
$rOriginFile = @fopen($originFile, 'r');
if ($rOriginFile !== false) {
$originID = fread($rOriginFile, 32);
fclose($rOriginFile);
}
if ($originID === false) {
$originID = '';
}
}
$params[] = new XML_RPC_Value($originID, 'string');
// Add the registered email address
$params[] = new XML_RPC_Value(OA_Dal_ApplicationVariables::get('sync_registered_email'), 'string');
// Create the XML-RPC request message
$msg = new XML_RPC_Message("OpenX.Sync", $params);
// Send the XML-RPC request message
if ($response = $client->send($msg, 10)) {
// XML-RPC server found, now checking for errors
//.........这里部分代码省略.........