Welcome Guest, Not a member yet? Register   Sign In
No db results on staging server?
#1

[eluser]kilishan[/eluser]
Here's a new one to me.

Code is working fine on my development box, but when it gets uploaded to the staging server for testing, it seems that nothing that ever connects to the database ever gets any information back. Every place that it does

Code:
if ($query->num_rows() > 0)
{ ... }

it's giving me a fatal error

Code:
PHP Fatal error:  Call to a member function num_rows() on a non-object

The staging server is runnig Ubuntu 10, PHP 5.3.2 and MySQL 5.1.41. The db config file is set to:

Code:
$db['test']['hostname'] = "localhost";
$db['test']['username'] = "...";
$db['test']['password'] = "...";
$db['test']['database'] = "...";
$db['test']['dbdriver'] = "mysql";
$db['test']['dbprefix'] = "";
$db['test']['pconnect'] = TRUE;
$db['test']['db_debug'] = TRUE;
$db['test']['cache_on'] = FALSE;
$db['test']['cachedir'] = "";
$db['test']['char_set'] = "utf8";
$db['test']['dbcollat'] = "utf8_general_ci";

(username, etc removed)

Any ideas what would be causing this? There is data in the database, same as the db on the dev server...
#2

[eluser]WanWizard[/eluser]
Are you sure a connection to the database is made?

If you have error reporting disabled (or display_errors off), you won't see anything, but the database object will not be created, for example if your try it on a PHP install without database drivers.
#3

[eluser]kilishan[/eluser]
Yeah, I've got errors turned on, and had the db user set up incorrectly before so it was giving me the unable to connect to the db error. I've resolved that, though, and am now hitting this error. I've tried modifying the persistent connection and driver info in the db config file with no success.
#4

[eluser]WanWizard[/eluser]
Are you sure the connection is ok?

Can you do a 'var_dump($query)' before that num_rows() check, to see if you really have the proper object?
#5

[eluser]kilishan[/eluser]
Hmmm... maybe it's not. The var_dump is returning boolean false.

Well, crap. Smile This is the first time I've had to setup a server from scratch. What fun.

Any suggestions on the best way to conquer this beast?

Thanks!
#6

[eluser]WanWizard[/eluser]
The query object ( a instance of the CI_DB_Result class ) is created and returned by $this->db->query().

This doesn't happen when:
- the query string is empty -> returns FALSE
- when the query failed to run -> display error or returns FALSE
- when is was a write query (INSERT, UPDATE, etc), returns TRUE
- when no return object is needed (currently only for Oracle SP's)

In these cases $query won't be an object. If this is happening, you need better error checking in your code...

My guess is that db errors are switched off in the config, and you have an error, so FALSE is returned.
#7

[eluser]kilishan[/eluser]
Doh! You're right. Looks like it's grabbing the production server db connection values (which had errors turned off...)

Thanks for all of the help, WanWizard!




Theme © iAndrew 2016 - Forum software by © MyBB