In my wordpress theme, I created a file called update.php. I can access this URL by
http://mydomain.com/wp-content/themes/mytheme/update.php
Here is the code inside update.php
global $wpdb;
// do some more stuff here
$wpdb->update( 'twitter_followers', array('count' => $followers), array('id' => '1') );
echo 'done';
When I go to this page I get this error.
PHP Fatal error: Call to a member function update() on a non-object in /var/www/vhosts/mydomain.com/subdomains/mytheme/httpdocs/wp-content/themes/mytheme/update.php on line 34
Any ideas on how I can fix this?
Also note, I did created twitter_followers table in my database.
The issue is that you don’t have $wpdb yet, since your update.php is not part of wordpress. When you go to update.php wordpress is never loaded, so you get the non-object error. Try adding this line to the top of your update.php file, obviously changing the path:
the path will probably look something like this in a normal installation: