Here's the code I'm trying to make work:
<?php
class database {
var $connection;
function database($host,$username,$password,$database){
$this->connection = mysql_connect($host, $username, $password);
mysql_select_db($database,$this->connection);
}
function query($query){
$query = mysql_query($query,$this->connection);
return $query;
}
}
$db = new database("localhost","root","password","database1");
$db2 = new database("SERVER2","root","password","database2");
$sql = $db->query("SELECT * FROM users WHERE name = 'Yifan' LIMIT 1");
$row = mysql_fetch_assoc($sql);
var_dump($row);
$sql = $db2->query("SELECT * FROM users WHERE name = 'Yifan' LIMIT 1");
$row = mysql_fetch_assoc($sql);
var_dump($row);
?>
So, in case you didn't understand that, I want to have two or more connections to mysql using objects, but the problem is, I get "bool(false)" as the first result, and the correct response for the second one. Any idea on what I'm doing wrong, or if it is even possible? Thanks.