本文整理汇总了PHP中DB_DataObject::getDatabaseConnection方法的典型用法代码示例。如果您正苦于以下问题:PHP DB_DataObject::getDatabaseConnection方法的具体用法?PHP DB_DataObject::getDatabaseConnection怎么用?PHP DB_DataObject::getDatabaseConnection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DB_DataObject
的用法示例。
在下文中一共展示了DB_DataObject::getDatabaseConnection方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct(DB_DataObject $do, $values)
{
$this->do = $do;
if (!is_array($values)) {
throw new Exception('Values must be an array !');
}
$this->values = $values;
$this->db = $do->getDatabaseConnection();
}
示例2: connectToDatabase
/**
* Connect to the database.
*
* @return void
* @access public
*/
public static function connectToDatabase()
{
global $configArray;
if (!defined('DB_DATAOBJECT_NO_OVERLOAD')) {
define('DB_DATAOBJECT_NO_OVERLOAD', 0);
}
$options =& PEAR_Singleton::getStaticProperty('DB_DataObject', 'options');
// If we're using PostgreSQL, we need to set up some extra configuration
// settings so that unique ID sequences are properly registered:
if (substr($configArray['Database']['database'], 0, 5) == 'pgsql') {
$tables = array('comments', 'oai_resumption', 'resource', 'resource_tags', 'search', 'session', 'tags', 'user', 'user_list', 'user_resource');
foreach ($tables as $table) {
$configArray['Database']['sequence_' . $table] = $table . '_id_seq';
}
}
$options = $configArray['Database'];
if (substr($configArray['Database']['database'], 0, 5) == 'mysql') {
// If we're using MySQL, we need to make certain adjustments (ANSI
// quotes, pipes as concatenation operator) for proper compatibility
// with code built for other database systems like PostgreSQL or Oracle.
$obj = new DB_DataObject();
$conn = $obj->getDatabaseConnection();
$conn->query("SET @@SESSION.sql_mode='ANSI_QUOTES,PIPES_AS_CONCAT'");
} else {
if (substr($configArray['Database']['database'], 0, 4) == 'oci8') {
// If we are using Oracle, set some portability values:
$temp_db = new DB_DataObject();
$db =& $temp_db->getDatabaseConnection();
$db->setOption('portability', DB_PORTABILITY_NUMROWS | DB_PORTABILITY_NULL_TO_EMPTY);
// Update the date format to fix issues with Oracle being evil
$db->query("ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:MI:SS'");
}
}
}
示例3: getTagsArray
/**
* @param DB_DataObject $obj the recordset on which the select query will be executed
*/
public function getTagsArray($obj)
{
if (is_array($obj->_tagplugin_cache)) {
return $obj->_tagplugin_cache;
}
if (empty($obj->tagplugin_cache)) {
$tag = DB_DataObject::factory('tag');
$dbo = DB_DataObject::factory('tag_record');
$dbo->tagged_table = $obj->tableName();
$dbo->record_id = $obj->pk();
$tag->selectAdd();
$tag->selectAdd('tag.id,tag.strip');
$tag->joinAdd($dbo);
$tag->selectAs($dbo, 'link_%s');
$tag->find();
$obj->tagplugin_cache = '|';
while ($tag->fetch()) {
if (empty($tag->strip)) {
continue;
}
$obj->tagplugin_cache .= $tag->strip . '|';
$obj->_tagplugin_cache[] = $tag->strip;
}
$db = $obj->getDatabaseConnection();
$query = sprintf('UPDATE %s SET tagplugin_cache=:cacheval where %s = :pkval', $db->quoteIdentifier($obj->tableName()), $db->quoteIdentifier($obj->pkName()));
$sth = $db->prepare($query, array('text', 'text'));
if (PEAR::isError($sth)) {
throw new Exception($sth->getMessage() . ' HINT: check if your table has a tagplugin_cache field');
}
$sth->execute(array('cacheval' => $obj->tagplugin_cache, 'pkval' => $obj->pk()));
}
$obj->_tagplugin_cache = explode('|', $obj->tagplugin_cache);
return $obj->_tagplugin_cache;
}