Can you help me with this? I have 2 identical tables in the product. But these tables are from 2 databases. My problem is I can't access the second database. I created a helper for connecting new database but it won't work. In my product form I have a field with checkbox. If you click all the checkbox the data will be inserted in all the checked database. By the way the value of my checkboxes are database names. I am configuring this in the model. But it doesn't work.
Here's a bit of my code:
Code: Select all
public function addProduct($data) {
if(isset($data['product_store'])){
for($x = 0; $x < sizeof($data['product_store']); $x++) {
fCloseDb();
fConnect('localhost','root','',$data['product_store'][$x]);
$this->insertData($data);
fCloseDb();
}
} else {
fdie($data);
$this->insertData($data);
}
}
Code: Select all
function fConnect($hostname, $username, $password, $database) {
$connect = mysqli_connect($hostname, $username, $password, $database);
if(mysqli_connect_errno()) {
die('Error in database connection: '.mysqli_connect_error());
} else {
fprintr('connect ok!');
}
}
function fCloseDb() {
mysql_close();
}
Code: Select all
[product_store] => Array
(
[0] => mtr_s6
[1] => mtr_s7
)