Project

General

Profile

Feature #17544 ยป round_robin_mysql_select.diff

Administrator Admin, 2007-08-20 22:29

View differences:

t3lib/class.t3lib_db.php 2007-08-15 11:52:34.000000000 +0200
// Default link identifier:
var $link = FALSE;
var $slaveLink = FALSE;
......
* @return pointer MySQL result pointer / DBAL object
*/
function exec_SELECTquery($select_fields,$from_table,$where_clause,$groupBy='',$orderBy='',$limit='') {
$res = mysql_query($this->SELECTquery($select_fields,$from_table,$where_clause,$groupBy,$orderBy,$limit), $this->link);
$res = mysql_query($this->SELECTquery($select_fields,$from_table,$where_clause,$groupBy,$orderBy,$limit), $this->getMysqlLink());
if ($this->debugOutput) $this->debug('exec_SELECTquery');
return $res;
}
function getMysqlLink()
{
$rand = rand(0, (count($GLOBALS["TYPO3_CONF_VARS"]['SYS']['slave_db_handler'])+1));
if ($rand > 0)
{
return $this->createMysqlLink( (--$rand) );
}
else
{
return $this->link;
}
}
function createMysqlLink($nr)
{
if (class_exists('t3lib_beUserAuth') || file_exists( $_SERVER["DOCUMENT_ROOT"] . "/" . $GLOBALS["TYPO3_CONF_VARS"]['SYS']['slave_db_handler'][$nr]['dead_file']))
{
return $this->link;
}
if (isset($this->slaveLink[$nr]))
return $this->slaveLink[$nr];
$this->slaveLink[$nr] = @mysql_connect( $GLOBALS["TYPO3_CONF_VARS"]['SYS']['slave_db_handler'][$nr]['typo3_db_host'], $GLOBALS["TYPO3_CONF_VARS"]['SYS']['slave_db_handler'][$nr]['typo3_db_username'], $GLOBALS["TYPO3_CONF_VARS"]['SYS']['slave_db_handler'][$nr]['typo3_db_password']);
if (!$this->slaveLink[$nr])
{
/* create dead lock file */
if (isset($GLOBALS["TYPO3_CONF_VARS"]['SYS']['slave_db_handler'][$nr]['dead_file']) && $GLOBALS["TYPO3_CONF_VARS"]['SYS']['slave_db_handler'][$nr]['dead_file'] != '')
{
$file = fopen($_SERVER["DOCUMENT_ROOT"] . "/" . $GLOBALS["TYPO3_CONF_VARS"]['SYS']['slave_db_handler'][$nr]['dead_file'], "w");
fputs($file, mysql_error());
fclose($file);
}
return $this->link;
}
mysql_select_db($GLOBALS["TYPO3_CONF_VARS"]['SYS']['slave_db_handler'][$nr]['typo3_db'] , $this->slaveLink[$nr]);
return $this->slaveLink[$nr];
}
/**
* Creates and executes a SELECT query, selecting fields ($select) from two/three tables joined
* Use $mm_table together with $local_table or $foreign_table to select over two tables. Or use all three tables to select the full MM-relation.
......
*/
function sql_fetch_assoc($res) {
$this->debug_check_recordset($res);
return mysql_fetch_assoc($res);
}
    (1-1/1)