I’d be grateful for any help on sorting this please. The code works perfectly on a live site but when I try to integrate it with WordPress I get the error.
The error means that whatever is in $GLOBALS[$dblink] (if anything) is not an object, so somewhere outside of this function $GLOBALS[$dblink] is not being set correctly.
It’s my first day in my new job and I’m trying to get the dynamic header from out site to work with WordPress. When I try I get just a blank page with that error. On the website itself there’s no errors and it works no problems.
I’m sorry I don’t quite understand. That function is called on lots of files/pages and is used to load the database. As I say this is my first day in the job so I’m still trying to find my way round and where different functions are.
To resolve this issue, where ever your globals are being set, add this line:
$GLOBALS['dbdebug'] = true;
Then when you’re done, change it to this (do NOT remove it)
$GLOBALS['dbdebug'] = false;
It looks like the code was written with some rudimentary debug logging added in, but is only used when a global flag is set. Then when it got moved to production, someone removed the global value set instead of just setting it to false.
Wow. I should have just stayed out of this thread. Your OP is a little misleading. Your initial post referenced a line number which was the debug, which is what my last reply was to. But your line counts are obviously off (are you using an IDE which provides line numbers?), since the error is on the select_db() line.
OK, the error is a mismatch somewhere along the way. You’re getting an error because the $GLOBALS[$dblink] doesn’t exist in the context being run.
So somewhere in your code, you’ve got a call to a database which doesn’t exist. In other words, you’ve got a call which is something like this:
usedb('TableName', 'ThisIsMyLink');
For that to work you’ve got to have something like one of these two lines occur BEFORE the call to the usedb method:
$ThisIsMyLink = new mysqli("localhost", "my_user", "my_password", "test");
or
$GLOBALS['ThisIsMyLink'] = new mysqli("localhost", "my_user", "my_password", "test");
It’s just been suggested that I include the db.inc file first then use 'usedb( “blog”,“dbLinkInt” ); it should work, but I really don’t know which part I should change? Sorry to ask such dumb questions but this is my first day in the job and I’ve very new to php
Also the file is used as part of the cms for the site so I’m worried about changing too much
If the db.inc file is where the database configuration is stored, then yes it probably will work - that should have been one of the first instructions your co-workers gave you before throwing you to the wolves.
Just a thought - do you know PHP at all? If not, you’re REALLY going to do some studying to get your feet underneath you. This command is basic, php 101.