Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Database Connection on extension.php when not signed in
I try to make a database query on the extension.php when a user is not logged in, but I only get errors.
When a user is logged in all works fine...
and then
I don't know what's wrong, because the query works fine when a user is logged in...
Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource
When a user is logged in all works fine...
$Context->PageTitle = $Context->GetDefinition('MyExtension');
$Menu->CurrentTab = 'MyExtension';
$Body->CssClass = 'MyExtensionContainer';
$Content = $Context->ObjectFactory->NewContextObject($Context, 'Content');
$Page->AddRenderControl($Content, $Configuration["CONTROL_POSITION_BODY_ITEM"]);
and then
class Content {
function Content() {
global $Context;
$res = mysql_query("SELECT ...",$Context->Database->Connection);
$row = mysql_fetch_row($res); <<-- Here the error appears
....
}
}
I don't know what's wrong, because the query works fine when a user is logged in...
0
This discussion has been closed.
Comments
if (!$Context->Database->Connection) { $Context->Database->Connection = @mysql_connect($Context->Configuration['DATABASE_HOST'],$Context->Configuration['DATABASE_USER'],$Context->Configuration['DATABASE_PASSWORD']); @mysql_select_db($Context->Configuration['DATABASE_NAME'], $Context->Database->Connection); }
If I remove the code and go (without logged in) to the account Page the queries work fine! Only at the extension Page they don't
But try this instead of your connection checking code:
$Context->Database->GetConnection();
That will check for a connection. If one isn't found, it will create it and you should be able to move forward properly.