News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

No Database selected error

Started by Tetrahydrocannabinol, March 24, 2015, 05:19:21 PM

Previous topic - Next topic

Tetrahydrocannabinol

Well.. I don't really know what happen, but randomly a couple parts of my website decided to break.

I added some text to where my forum prints out the date. It uses a value from MySQL, and I copied the format from another part of code I found in my Subs.php.

The exact error:
QuoteNo database selected
File: /home/my_site_folder/public_html/Sources/Subs.php
Line: 3200
Back

And then on line 3200 of Subs.php:
$loaded = true;
$context['in_maintenance'] = !empty($maintenance);
$context['current_time'] = timeformat(time(), false);
$res = $smcFunc['db_query']('', 'SELECT `value` FROM `smf_settings` WHERE `variable` = "players_online"', array());// Line 3200


At first I had the "smf_" as "{db_prefix}" but I thought that was the cause of the error, so I changed it to what I had the prefix as.
And that did fix one part of my website.. But 2 parts are still broken.

I'm stumped as to why this is causing an error.

Arantor

You should always use {db_prefix} - it's important, and vital if using SSI.

Though if you're using SSI you don't need to query the settings table because the entirety of smf_settings is loaded into $modSettings in both regular and SSI modes...

Tetrahydrocannabinol

Quote from: Arantor on March 24, 2015, 05:21:32 PM
You should always use {db_prefix} - it's important, and vital if using SSI.

Though if you're using SSI you don't need to query the settings table because the entirety of smf_settings is loaded into $modSettings in both regular and SSI modes...
What about if it's a custom value I added to the table? would I still use $modSettings? I also need it to update as soon as it changes in the database.

Arantor

EVERYTHING is loaded from the table when SMF starts. And is reloaded every page.

If you use updateSettings() to update things, it'll even update $modSettings for you.

Tetrahydrocannabinol

Quote from: Arantor on March 24, 2015, 05:55:01 PM
EVERYTHING is loaded from the table when SMF starts. And is reloaded every page.

If you use updateSettings() to update things, it'll even update $modSettings for you.

Alright thank you. I changed it to modSettings and the pages seem to be loading fine now.

Advertisement: