Welcome Guest, Not a member yet? Register   Sign In
2nd DB connection able to insert, but not get
#1

[eluser]c_h_r_i_s[/eluser]
I have a function in my controller that connects to a database other than the one in the config directory and I am able to insert into tables, but when I run a get the page shows up blank and doesn't redirect to the right page. Has anyone dealt with a similar problem?

$config = ..
$DB = $this->load->database($config, TRUE);
return $DB;

...

$DB->get('table'); doesn't work

Any suggestions on how to debug or fix are appreciated.
#2

[eluser]Phil Sturgeon[/eluser]
What is the actual code you are using to create this query?

Why are you returning $DB?

What "doesn't work"?

Be a little more specific. The more information we have the easier we can help you.
#3

[eluser]c_h_r_i_s[/eluser]
function connect(){
$config = ..
$config['dbdriver'] = "mysql";
$config['dbprefix'] = "";
$config['pconnect'] = TRUE;
$config['db_debug'] = FALSE;
$config['cache_on'] = TRUE;
$config['cachedir'] = "";
$config['char_set'] = "utf8";
$config['dbcollat'] = "utf8_general_ci";
$DB = $this->load->database($config, TRUE);
return $DB;
}

function func2(){
$DB = $this->connect();
$DB->get(‘table’); doesn’t work
}

I have the connect in its own function because there are multiple functions that need to make queries to the 2nd database.
using:
$DB->set('test','test');
$DB->insert('test');

works fine, but when using $DB->get('test'); causes the site to not load the page and you have to hit the back button to continue on to the site. Nothing after the get line is executed so it's hard to debug and turning db_debug to true doesn't provide anything in this case.
#4

[eluser]c_h_r_i_s[/eluser]
Has anyone had problems with a 2nd database connection?
#5

[eluser]Phil Sturgeon[/eluser]
What is the following function supposed to do?

Code:
function func2(){
$DB = $this->connect();
$DB->get('table');
}

It doesn't return anything or pass any data anywhere, I wouldn't expect this to work!


Code:
function func2(){
$DB = $this->connect();
$query = $DB->get('table');

return $query->result();
}

or the sexier PHP 5 method chaining version:


Code:
function func2(){
$DB = $this->connect();
return $DB->get('table')->result();
}

You have result(), result_array(), row() & row_array().

Hope this helps!
#6

[eluser]c_h_r_i_s[/eluser]
I guess I should've said more.

$DB->where('login',$username);
$query=$DB->get('table'); <-- nothing is executed after here
if (!$query->result()) {
[enter data into database]
}

I put var_dump($DB) after the if statement and it doesn't get shown on the page. only a blank page and you have to hit the back button to continue on to the next page.
#7

[eluser]Phil Sturgeon[/eluser]
Nothing is executed? How do you know?

var_dump($query);

echo $DB->last_query();

Try to debug, let me know whats going on so I can help! If you just say something doesnt work we cant help you.
#8

[eluser]c_h_r_i_s[/eluser]
I tried echo $DB->last_query(); after I called the get and it still shows a blank page. I'm not sure how to debug since this function is called before loading the page. I don't believe it is a database error since nothing came up when I set db_debug to true.
Keep in mind i'm relatively new to PHP, but I have a lot of other programming experience.




Theme © iAndrew 2016 - Forum software by © MyBB