Post by rochellecanale » Tue Aug 19, 2014 2:41 pm

Hi guys,

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);

	}

}
Here's my helper:

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();
	
}
sample data from POST

Code: Select all

[product_store] => Array
(
            [0] => mtr_s6
            [1] => mtr_s7
)


Posts

Joined
Mon Apr 07, 2014 12:16 pm

Post by EvilHit » Wed Aug 27, 2014 1:17 pm

hey bud

this is for CodeIgniter but it mite help

https://ellislab.com/forums/viewthread/160029/#770145

New member

Posts

Joined
Fri Jun 06, 2014 6:53 pm
Who is online

Users browsing this forum: No registered users and 3 guests