06-06-2008, 06:52 PM
|
#1 (permalink)
|
|
The Contributor
Join Date: May 2008
Location: Denmark
Posts: 70
Thanks: 3
|
Mysql resources in array?
Isn't it possible to store multiple mysql connections to different databases in an array? So far i'm able to store them, but it is the same resource in both entries..
My print_r dump looks like this:
Code:
Array
(
[dev1] => Resource id #7
[pureftpd] => Resource id #7
)
My code looks like this:
PHP Code:
<?php //Check if ticket if (!defined('BACKEND_TICKET')) { die(); }
class database extends p101 { public $link = array(); public $db = 'mysql';
public function connect() { global $p101; static $host = 'localhost'; static $user = ''; static $pass = ''; static $name = array( 1 => 'dev1', 2 => 'pureftpd' ); switch($this->db) { case 'mysql': { foreach($name as $val) { if ($this->link[$val] = mysql_connect($host, $user, $pass)) { if (mysql_select_db($val, $this->link[$val])) { return(true); } else { $p101->error[] = 'Unable to select database: ' . $val . '!'; } } else { $p101->error[] = 'Unable to connect to database!'; } } break; } } } public function query($sql,$return = null,$link) { $buffer = array(); switch($this->db) { case 'mysql': { switch($return) { case 'assoc': { return(mysql_fetch_assoc(mysql_query($sql,$this->link[$link]))) or die(mysql_error()); } case 'array': { //return(mysql_fetch_assoc(mysql_query($sql,$this->link[$link]))); } case 'exec': { if (mysql_query($sql,$this->link[$link])) { return(true); } else { return(false); } } default: { return(mysql_query($sql,$this->link[$link])); } } break; } } } public function __destruct() { foreach($this->link as $key => $val) { mysql_close($this->link[$key]); } } }
?>
Any ideas how to do this? Or is it just not possible?
|
|
|
|